March 2017
Intermediate to advanced
226 pages
5h 13m
English
Currying in Swift (and other programming languages) transforms a function that accepts multiple arguments into a series of partially applied functions using a subset of those arguments. The technique was developed by Moses Schönfinkel and Haskell Curry, which explains its curious name.
Partial application decomposes a function, allowing you to call it in stages, creating a primed, reusable method. In practice, it’s similar to using argument defaults when you don’t know at compile time what those defaults will be. Currying creates a customizable system, allowing you to set those defaults at run time.
Here’s a typical multistage example:
| | public func projected(function f: @escaping (CGFloat) -> CGFloat |
Read now
Unlock full access