July 2017
Intermediate to advanced
284 pages
6h 45m
English
One cool thing to note is that instance methods are actually curried functions in Swift.
The basic idea behind currying is that a function can be partially applied, meaning that some of its parameter values can be specified (bound) before the function is called. Partial function application yields a new function.
So given that I have a class:
| | class MyHelloWorldClass { |
| | |
| | func helloWithName(name: String) -> String { |
| | return "hello, \(name)" |
| | } |
| | } |
I can create a variable that points to the class’s helloWithName function:
| | let helloWithNameFunc = MyHelloWorldClass.helloWithName |
| | // MyHelloWorldClass -> (String) -> String |
My new helloWithNameFunc is of type MyHelloWorldClass -> (String) -> String ...
Read now
Unlock full access