-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
NSArray+select.h
47 lines (32 loc) · 989 Bytes
/
NSArray+select.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#import <Foundation/NSArray.h>
@interface NSArray (YOLOSelect)
/**
Returns a new array containing all elements for which the given block
returns `YES`.
id rv = @[@1, @2, @3, @4].select(^(NSNumber *n){
return n.intValue % 2 == 0;
});
// rv => @[@2, @4]
Alternatively pass a `Class` object:
id rv = @[@1, @"1", @{}].select(NSString.class)
// rv => @[@"1"]
Convenient when searching for specifc subviews.
self.view.subviews.select(UITextField.class);
Though you may need an `allSubviews` pod.
@see -reject
*/
- (NSArray *(^)(id blockOrClass))select;
/**
Returns a new array containing all elements for which the given block
returns `NO`.
id rv = @[@1, @2, @3, @4].reject(^(NSNumber *n){
return n.intValue % 2 == 0;
});
// rv => @[@1, @3]
Alternatively pass a `Class` object:
id rv = @[@1, @"1", @{}].reject(NSNumber.class)
// rv => @[@"1", @{}]
@see -select
*/
- (NSArray *(^)(id blockOrClass))reject;
@end