-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathNSArray+map.h
More file actions
29 lines (21 loc) · 759 Bytes
/
NSArray+map.h
File metadata and controls
29 lines (21 loc) · 759 Bytes
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
#import <Foundation/NSArray.h>
@interface NSArray (YOLOMap)
/**
Invokes the given block once for each element of self. Creates a new
array containing the values returned by the block.
id rv = @[@1, @2, @3, @4].map(^(NSNumber *n){
return @(n.intValue * n.intValue);
});
// rv => @[@1, @4, @9, @16]
If the given block returns nil, that element is skipped in the returned
array.
The given block can have up to three parameters, the first is an element
in the array, the second that element’s index, and the third the array
itself.
The second parameter can be a primitive (eg. `int`), or an `NSNumber *`:
@"YOLO".split(@"").map(^(NSString *letter, int index){
//…
});
*/
- (NSArray *(^)(id block))map;
@end