Created
September 7, 2015 22:48
-
-
Save vilhalmer/122f2ea8d76df9ac7e3b to your computer and use it in GitHub Desktop.
This file contains 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
typedef BOOL (^ FilterBlock)(id _); | |
@implementation NSArray (Bifurcate) | |
- (void)bifurcate:(FilterBlock)test passing:(out NSArray **)passing failing:(out NSArray **)failing | |
{ | |
NSMutableArray * passed = [NSMutableArray array]; | |
NSMutableArray * failed = [NSMutableArray array]; | |
for (id thing in self) { | |
if (test(thing)) { | |
[passed addObject:thing]; | |
} | |
else { | |
[failed addObject:thing]; | |
} | |
} | |
*passing = passed; | |
*failing = failed; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment