Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 70 lines (61 sloc) 2.511 kb
a8bce05 @WH-NewMedia Add wh-app-ios files.
WH-NewMedia authored
1 /*
2 * This project constitutes a work of the United States Government and is
3 * not subject to domestic copyright protection under 17 USC § 105.
4 *
5 * However, because the project utilizes code licensed from contributors
6 * and other third parties, it therefore is licensed under the MIT
7 * License. http://opensource.org/licenses/mit-license.php. Under that
8 * license, permission is granted free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the conditions that any appropriate copyright notices and this
15 * permission notice are included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 //
28 // NSArray+WHAdditions.m
29 // WhiteHouseApp
30 //
31 //
32
33 #import "NSArray+WHAdditions.h"
34
35 @implementation NSArray (WHAdditions)
36
37 - (NSArray *)partitionedArrayUsingBlock:(id (^)(id))block
38 {
39 NSMutableArray *partitions = [NSMutableArray array];
40 id testValue = [[NSObject alloc] init];
41 for (id obj in self) {
42 id blockValue = block(obj);
43 if (![testValue isEqual:blockValue]) {
44 testValue = blockValue;
45 [partitions addObject:[NSMutableArray array]];
46 }
47 [(NSMutableArray *)[partitions lastObject] addObject:obj];
48 }
49 return partitions;
50 }
51
52 - (NSArray *)filteredArrayUsingBlock:(BOOL (^)(id))block
53 {
54 return [self filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
55 return block(evaluatedObject);
56 }]];
57 }
58
59 - (NSArray *)mappedArrayUsingBlock:(id (^)(id))block
60 {
61 NSMutableArray *result = [NSMutableArray arrayWithCapacity:[self count]];
62 for (id obj in self) {
63 [result addObject:block(obj)];
64 }
65 return result;
66 }
67
68
69 @end
Something went wrong with that request. Please try again.