Permalink
Browse files

select and reject return empty array/dictionary/set instead of nil, to

allow a more functional coding style
  • Loading branch information...
Paul Bridger
Paul Bridger committed Feb 19, 2012
1 parent c9525fa commit 903096da9d923d45fc246935ec675bc1f63b85ab
Showing with 4 additions and 30 deletions.
  1. +2 −12 BlocksKit/NSArray+BlocksKit.m
  2. +0 −6 BlocksKit/NSDictionary+BlocksKit.m
  3. +2 −12 BlocksKit/NSSet+BlocksKit.m
@@ -39,27 +39,17 @@ - (id)match:(BKValidationBlock)block {
- (NSArray *)select:(BKValidationBlock)block {
NSParameterAssert(block != nil);
- NSArray *result = [self objectsAtIndexes:[self indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
+ return [self objectsAtIndexes:[self indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
return block(obj);
}]];
-
- if (!result.count)
- return nil;
-
- return result;
}
- (NSArray *)reject:(BKValidationBlock)block {
NSParameterAssert(block != nil);
- NSArray *result = [self objectsAtIndexes:[self indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
+ return [self objectsAtIndexes:[self indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
return !block(obj);
}]];
-
- if (!result.count)
- return nil;
-
- return result;
}
- (NSArray *)map:(BKTransformBlock)block {
@@ -33,9 +33,6 @@ - (NSDictionary *)select:(BKKeyValueValidationBlock)block {
[list setObject:obj forKey:key];
}];
- if (!list.count)
- return nil;
-
return list;
}
@@ -49,9 +46,6 @@ - (NSDictionary *)reject:(BKKeyValueValidationBlock)block {
[list setObject:obj forKey:key];
}];
- if (!list.count)
- return nil;
-
return list;
}
@@ -38,27 +38,17 @@ - (id)match:(BKValidationBlock)block {
- (NSSet *)select:(BKValidationBlock)block {
NSParameterAssert(block != nil);
- NSSet *list = [self objectsPassingTest:^BOOL(id obj, BOOL *stop) {
+ return [self objectsPassingTest:^BOOL(id obj, BOOL *stop) {
return (block(obj));
}];
-
- if (!list.count)
- return nil;
-
- return list;
}
- (NSSet *)reject:(BKValidationBlock)block {
NSParameterAssert(block != nil);
- NSSet *list = [self objectsPassingTest:^BOOL(id obj, BOOL *stop) {
+ return [self objectsPassingTest:^BOOL(id obj, BOOL *stop) {
return (!block(obj));
}];
-
- if (!list.count)
- return nil;
-
- return list;
}
- (NSSet *)map:(BKTransformBlock)block {

0 comments on commit 903096d

Please sign in to comment.