Source

MYUtilities / CollectionUtils.m

Diff from to

File CollectionUtils.m

     return result;
 }
 
+#if NS_BLOCKS_AVAILABLE
+- (NSArray*) my_map: (id (^)(id obj))block {
+    NSMutableArray* mapped = [[NSMutableArray alloc] initWithCapacity: self.count];
+    for (id obj in self) {
+        obj = block(obj);
+        if (obj)
+            [mapped addObject: obj];
+    }
+    NSArray* result = [[mapped copy] autorelease];
+    [mapped release];
+    return result;
+}
+
+- (NSArray*) my_filter: (int (^)(id obj))block {
+    NSMutableArray* filtered = [[NSMutableArray alloc] initWithCapacity: self.count];
+    for (id obj in self) {
+        if (block(obj))
+            [filtered addObject: obj];
+    }
+    NSArray* result = [[filtered copy] autorelease];
+    [filtered release];
+    return result;
+}
+#endif
+
 - (NSString*) my_compactDescription
 {
     NSMutableString *desc = [NSMutableString stringWithCapacity: 100];