-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathNSArray+pluck.h
More file actions
24 lines (17 loc) · 791 Bytes
/
NSArray+pluck.h
File metadata and controls
24 lines (17 loc) · 791 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
#import <Foundation/NSArray.h>
@interface NSArray (YOLOPluck)
/**
Returns a new array that is the result of calling the given method on
each element in the receiver.
MKShape *rhombas = [MKShape new]; rhombas.title = @"rhombas";
MKShape *ellipse = [MKShape new]; ellipse.title = @"ellipse";
MKShape *hexagon = [MKShape new]; hexagon.title = @"hexagon";
id rv = @[rhombas, ellipse, hexagon].pluck(@"title")
// rv => @[@"rhombas", @"ellipse", @"hexagon"]
id rv = @[rhombas, ellipse, hexagon].pluck(@"title.uppercaseString")
// rv => @[@"RHOMBAS", @"ELLIPSE", @"HEXAGON"]
NOTE: This is a convenience function for the common case of mapping
(`-map`) an array to the result of a method call on each element.
*/
- (NSArray *(^)(NSString *keypath))pluck;
@end