Higher-Order Functions
Higher-order functions are functions that can take another function as an argument or can return a function.
You have already worked with higher-order functions in this chapter and even written your own, like format(numbers:using:)
.
Let’s take a look at three higher-order functions from the standard library – map(_:)
, filter(_:)
, and reduce(_:_:)
– in the context of your imaginary volunteerism reports.
map(_:)
The Swift standard library provides an implementation of map(_:)
as a method on the Array
type.
It is used to transform an array’s contents.
You map an array’s contents from one value to another and put the new values into a new array.
Because map(_:)
is a higher-order function, you provide it with another ...
Get Swift Programming: The Big Nerd Ranch Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.