Functions as Return Types
Now that you have more experience with functions and closures, recall from Chapter 12 that every function has a function type that defines its parameter and return types.
For example, a function that takes a String argument and returns an Int has the function type of (String) -> Int.
Function types are frequently used to determine what sort of closure you need to satisfy a given parameter’s type or what sort of function needs to be returned.
Functions can return other functions as their return type. Remember your little town of Knowhere? It is time to make a function to improve your town. You are going to build some roads.
Listing 13.7 Return to Knowhere
import Cocoa let volunteerCounts = [1,3,40,32,2,53,77,13] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access