Skip to content

Instantly share code, notes, and snippets.

@vilhalmer
Created September 7, 2015 22:48
Show Gist options
  • Save vilhalmer/122f2ea8d76df9ac7e3b to your computer and use it in GitHub Desktop.
Save vilhalmer/122f2ea8d76df9ac7e3b to your computer and use it in GitHub Desktop.
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