Skip to content

Instantly share code, notes, and snippets.

@miguel12345
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save miguel12345/60e9872adb04f81ea5eb to your computer and use it in GitHub Desktop.

Select an option

Save miguel12345/60e9872adb04f81ea5eb to your computer and use it in GitHub Desktop.
Currying in Objective-c
//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