/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. #import "NSMutableIndexSet+BlocksKit.h"
  6. @implementation NSMutableIndexSet (BlocksKit)
  7. - (void)performSelect:(BKIndexValidationBlock)block {
  8. NSParameterAssert(block != nil);
  9. NSIndexSet *list = [self indexesPassingTest:^BOOL(NSUInteger idx, BOOL *stop) {
  10. return !block(idx);
  11. }];
  12. if (!list.count)
  13. return;
  14. [self removeIndexes:list];
  15. }
  16. - (void)performReject:(BKIndexValidationBlock)block {
  17. NSParameterAssert(block != nil);
  18. NSIndexSet *list = [self indexesPassingTest:^BOOL(NSUInteger idx, BOOL *stop) {
  19. return block(idx);
  20. }];
  21. if (!list.count)
  22. return;
  23. [self removeIndexes:list];
  24. }
  25. - (void)performMap:(BKIndexTransformBlock)block {
  26. NSParameterAssert(block != nil);
  27. NSMutableIndexSet *new = [self mutableCopy];
  28. [self enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
  29. [new addIndex:block(idx)];
  30. }];
  31. [self removeAllIndexes];
  32. [self addIndexes:[new autorelease]];
  33. }
  34. @end