forked from leuchtetgruen/Functional.m
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSArray+F.m
80 lines (62 loc) · 1.83 KB
/
NSArray+F.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// NSArray+F.m
// Functional
//
// Created by Hannes Walz on 07.04.12.
// Copyright 2012 leuchtetgruen. All rights reserved.
//
#import "NSArray+F.h"
@implementation NSArray(F)
- (void) each:(VoidIteratorArrayBlock) block {
[F eachInArray:self withBlock:block];
}
- (NSArray *) map:(MapArrayBlock) block {
return [F mapArray:self withBlock:block];
}
- (id) reduce:(ReduceArrayBlock) block withInitialMemo:(id) memo {
return [F reduceArray:self withBlock:block andInitialMemo:memo];
}
- (NSArray *) filter:(BoolArrayBlock) block {
return [F filterArray:self withBlock:block];
}
- (NSArray *) reject:(BoolArrayBlock) block {
return [F rejectArray:self withBlock:block];
}
- (BOOL) isValidForAll:(BoolArrayBlock) block {
return [F allInArray:self withBlock:block];
}
- (BOOL) isValidForAny:(BoolArrayBlock) block {
return [F anyInArray:self withBlock:block];
}
- (NSNumber *) countValidEntries:(BoolArrayBlock) block {
return [F countInArray:self withBlock:block];
}
- (id) max:(CompareArrayBlock) block {
return [F maxArray:self withBlock:block];
}
- (id) min:(CompareArrayBlock) block {
return [F minArray:self withBlock:block];
}
// This is really just an alias
- (NSArray *) sort:(NSComparator) block {
return [self sortedArrayUsingComparator:block];
}
- (NSDictionary *) group:(MapArrayBlock) block {
return [F groupArray:self withBlock:block];
}
// Just a helper method
- (id) first {
return [self objectAtIndex:0];
}
// Just a helper method
- (NSArray *) reverse {
return [[self reverseObjectEnumerator] allObjects];
}
+ (NSArray *) arrayFrom:(NSInteger) from To:(NSInteger) to {
NSMutableArray *mutArr = [NSMutableArray array];
for (NSInteger i=from; i <= to; i++) {
[mutArr addObject:[NSNumber numberWithInteger:i]];
}
return [NSArray arrayWithArray:mutArr];
}
@end