Created
February 22, 2015 13:21
-
-
Save flexaddicted/5ec379a4b08a52bb632a to your computer and use it in GitHub Desktop.
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
| // NSArray+FAPMap.h | |
| typedef id(^MapBlock)(id item); | |
| @interface NSArray (FAPMap) | |
| - (NSArray*)fap_map:(MapBlock)mapBlock; | |
| @end | |
| // NSArray+FAPMap.m | |
| @implementation NSArray (FAPMap) | |
| - (NSArray*)fap_map:(MapBlock)mapBlock { | |
| NSMutableArray* mapArray = [NSMutableArray arrayWithCapacity:[self count]]; | |
| for (id item in self) { | |
| id mappedItem = mapBlock(item); | |
| if(mappedItem) { | |
| [mapArray addObject:mappedItem]; | |
| } | |
| } | |
| return [NSArray arrayWithArray:mapArray]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment