/
Callables.m
33 lines (27 loc) · 935 Bytes
/
Callables.m
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
#import "Callables.h"
@implementation Callables
+ (id (^)(id))identity {
return [^(id item) { return item; } copy];
}
+ (NSString * (^)(NSString *))toUpperCase {
return [^(NSString *item) { return item.uppercaseString; } copy];
}
+(NSString * (^)(NSString *, NSString *))appendString {
return [^(NSString *left, NSString *right) { return [left stringByAppendingString:right]; } copy];
}
+ (ACCUMULATOR_TO_STRING)appendWithSeparator:(NSString *)separator {
return [^(id left, id right) {
return [[[left description] stringByAppendingString:separator] stringByAppendingString:[right description]];
} copy];
}
+ (CALLABLE_TO_STRING)upperCase {
return [^(id <NSObject> item) {
return [item description].uppercaseString;
} copy];
}
+ (CALLABLE_TO_NUMBER)increment {
return [^(NSNumber *item) {
return [NSNumber numberWithLong:item.longValue + 1];
} copy];
}
@end