PageRenderTime 53ms CodeModel.GetById 41ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 1//
 2//  NSMutableIndexSet+BlocksKit.m
 3//  BlocksKit
 4//
 5
 6#import "NSMutableIndexSet+BlocksKit.h"
 7
 8@implementation NSMutableIndexSet (BlocksKit)
 9
10- (void)performSelect:(BKIndexValidationBlock)block {
11	NSParameterAssert(block != nil);
12	
13	
14	NSIndexSet *list = [self indexesPassingTest:^BOOL(NSUInteger idx, BOOL *stop) {
15		return !block(idx);
16	}];
17	
18	if (!list.count)
19		return;
20	
21	[self removeIndexes:list];
22}
23
24- (void)performReject:(BKIndexValidationBlock)block {
25	NSParameterAssert(block != nil);
26	
27	
28	NSIndexSet *list = [self indexesPassingTest:^BOOL(NSUInteger idx, BOOL *stop) {
29		return block(idx);
30	}];
31	
32	if (!list.count)
33		return;
34	
35	[self removeIndexes:list];	
36}
37
38- (void)performMap:(BKIndexTransformBlock)block {
39	NSParameterAssert(block != nil);
40	
41	NSMutableIndexSet *new = [self mutableCopy];
42	
43	[self enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
44		[new addIndex:block(idx)];
45	}];
46	
47	[self removeAllIndexes];
48	[self addIndexes:[new autorelease]];
49}
50
51@end