Function Types
Each function you have been working with in this chapter has a specific type.
In fact, all functions do.
Function types are made up of the function’s parameter and return types.
Consider the sortedEvenOddNumbers(_:) function.
This function takes an array of integers as an argument and returns a tuple with two arrays of integers.
Thus, the function type for sortedEvenOddNumbers(_:) is expressed as ([Int]) -> ([Int], [Int]).
The function’s parameters are listed inside the left parentheses, and the return type comes after the ->.
You can read this function type as: “A function with one parameter that takes an array of integers and returns a tuple with two arrays containing integers.” For comparison, a function with no arguments ...
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