April 2017
Intermediate to advanced
316 pages
9h 33m
English
Swift functions can return a value, tuple, closure, or another function. The ability of a function to return a closure or function is an essential concept for FP as it empowers us to compose with functions. We will get into the use of it when we talk about first-class and higher-order functions.
Syntax-wise, we can specify that a function returns by providing ReturnType after ->. For instance, the following example returns String:
func functionName() -> String { }
Any function that has ReturnType in its definition should have a return keyword with the matching type in its body.
return types can be optionals in Swift, so the function becomes as follows for our previous example:
func functionName() -> String? ...
Read now
Unlock full access