TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Oliver Staats.
BLKFunctional is a small library to enable a bit of functional style programming in objective-c.
Categories on NSArray and NSString uses the library prefix "blk_", to avoid namespace clashes. The categories add the minimum number of functions to avoid namespace pollution.
// Assuming the following array
NSArray *numberArray = @[@2, @9, @66];
// 1. Conjoin, can join arrays, sets, dictionaries and objects
NSArray *arr1 = [numberArray blk_conjoin:@6 and:@7 ]; // arr1 = @[@2, @9, @66, @6, @7]
NSArray *arr2 = [numberArray blk_conjoin:@[@6, @7] ]; // arr2 = @[@2, @9, @66, @6, @7]
NSString *str1 = [@"[2" blk_conjoin:@", 9" and:@", 66]"]; // str1 = @"[2, 9, 66]"
NSString *str2 = [@"[" blk_conjoin:numberArray interpose:@", " end:@"]" ];
// str2 = @"[2, 9, 66]"
// 2. Convenience expression macros
// Below, the type of argument "p1" is NSNumber, so ide code completion is available
NSArray *arr3 = [numberArray blk_map:BLKFnN(@([p1 doubleValue] + 2)) ];
// 3. Functions on NSArray
NSArray *arr4 = [numberArray blk_map:^(NSNumber *p1) {
return @([p1 doubleValue] + 2);
}];
// 4. (OR) If you absolutely can't have a category
NSArray *arr5 = [BLKFunction mapArray:numberArray withBlock:^(NSNumber *p1) {
return @([p1 doubleValue] + 2);
}];
// For category names and expression macros, #import BLKCatFunction.h
// (OR) To forgo categories, #import BLKFunction.h (and optionally, #import BLKMacro.h)
Available on NSArray as Category methods (with prefix "blk_")
Available on NSString as Category method (with prefix "blk_")
Additionally, available via BLKFunction.h (already imported if you are using categories)
Enumeration "Stop" short circuit (like on enumerateObjectsUsingBlock:) Via returning constant BLKStopProcessing, available to