/BlocksKit/NSIndexSet+BlocksKit.m
http://github.com/zwaldowski/BlocksKit · Objective C · 75 lines · 49 code · 22 blank · 4 comment · 9 complexity · d220b9e8ebb24c1f53bcd7527f3f353e MD5 · raw file
- //
- // NSIndexSet+BlocksKit.m
- // BlocksKit
- //
- #import "NSIndexSet+BlocksKit.h"
- @implementation NSIndexSet (BlocksKit)
- - (void)each:(BKIndexBlock)block {
- NSParameterAssert(block != nil);
-
- [self enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
- block(idx);
- }];
- }
- - (void)apply:(BKIndexBlock)block {
- NSParameterAssert(block != nil);
-
- [self enumerateIndexesWithOptions:NSEnumerationConcurrent usingBlock:^(NSUInteger idx, BOOL *stop) {
- block(idx);
- }];
- }
- - (NSUInteger)match:(BKIndexValidationBlock)block {
- NSParameterAssert(block != nil);
-
- return [self indexPassingTest:^BOOL(NSUInteger idx, BOOL *stop) {
- return block(idx);
- }];
- }
- - (NSIndexSet *)select:(BKIndexValidationBlock)block {
- NSParameterAssert(block != nil);
-
- NSIndexSet *list = [self indexesPassingTest:^BOOL(NSUInteger idx, BOOL *stop) {
- return block(idx);
- }];
-
- if (!list.count)
- return nil;
-
- return list;
- }
- - (NSIndexSet *)reject:(BKIndexValidationBlock)block {
- NSParameterAssert(block != nil);
- NSIndexSet *list = [self indexesPassingTest:^BOOL(NSUInteger idx, BOOL *stop) {
- return !block(idx);
- }];
-
- if (!list.count)
- return nil;
-
- return list;
- }
- - (NSIndexSet *)map:(BKIndexTransformBlock)block {
- NSParameterAssert(block != nil);
-
- NSMutableIndexSet *list = [NSMutableIndexSet indexSet];
-
- [self enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
- [list addIndex:block(idx)];
- }];
-
- if (!list.count)
- return nil;
-
- return list;
- }
- @end