Last active
August 29, 2015 14:06
-
-
Save miguel12345/60e9872adb04f81ea5eb to your computer and use it in GitHub Desktop.
Currying in Objective-c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Define the methods | |
| -(int) sumA:(int) a withB:(int)b { | |
| return a + b; | |
| } | |
| -(int (^)(int)) sumWithA:(int)a { | |
| int (^blockName)(int) = ^int(int b) { | |
| return [self sumA:a withB:b]; | |
| }; | |
| return blockName; | |
| } | |
| //Use them | |
| NSLog(@"%d",[self sumA:2 withB:4]); | |
| int (^sumWith2)(int) = [self sumWithA:2]; | |
| NSLog(@"%d",sumWith2(4)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment