/BlocksKit/NSMutableIndexSet+BlocksKit.m
http://github.com/zwaldowski/BlocksKit · Objective C · 51 lines · 30 code · 17 blank · 4 comment · 5 complexity · 3ff366745e3ea5cacae9624c5823f1a8 MD5 · raw file
- //
- // NSMutableIndexSet+BlocksKit.m
- // BlocksKit
- //
- #import "NSMutableIndexSet+BlocksKit.h"
- @implementation NSMutableIndexSet (BlocksKit)
- - (void)performSelect:(BKIndexValidationBlock)block {
- NSParameterAssert(block != nil);
-
-
- NSIndexSet *list = [self indexesPassingTest:^BOOL(NSUInteger idx, BOOL *stop) {
- return !block(idx);
- }];
-
- if (!list.count)
- return;
-
- [self removeIndexes:list];
- }
- - (void)performReject:(BKIndexValidationBlock)block {
- NSParameterAssert(block != nil);
-
-
- NSIndexSet *list = [self indexesPassingTest:^BOOL(NSUInteger idx, BOOL *stop) {
- return block(idx);
- }];
-
- if (!list.count)
- return;
-
- [self removeIndexes:list];
- }
- - (void)performMap:(BKIndexTransformBlock)block {
- NSParameterAssert(block != nil);
-
- NSMutableIndexSet *new = [self mutableCopy];
-
- [self enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
- [new addIndex:block(idx)];
- }];
-
- [self removeAllIndexes];
- [self addIndexes:[new autorelease]];
- }
- @end