public
Description: Objective-C category to add Python-like map, filter and reduce methods to Cocoa NSArray.
Homepage:
Clone URL: git://github.com/nst/nsarray-functional.git
name age message
file Functional.1 Tue Feb 24 02:47:13 -0800 2009 initial import [nst]
file Functional.m Tue Feb 24 02:47:13 -0800 2009 initial import [nst]
directory Functional.xcodeproj/ Tue Feb 24 02:47:13 -0800 2009 initial import [nst]
file Functional_Prefix.pch Tue Feb 24 02:47:13 -0800 2009 initial import [nst]
file NSArray+Functional.h Tue Feb 24 02:47:13 -0800 2009 initial import [nst]
file NSArray+Functional.m Tue Feb 24 02:47:13 -0800 2009 initial import [nst]
file NSInvocation+Functional.h Tue Feb 24 02:47:13 -0800 2009 initial import [nst]
file NSInvocation+Functional.m Tue Feb 24 02:47:13 -0800 2009 initial import [nst]
file NSString+Cat.h Tue Feb 24 02:47:13 -0800 2009 initial import [nst]
file NSString+Cat.m Tue Feb 24 02:47:13 -0800 2009 initial import [nst]
file README Mon Sep 28 13:06:14 -0700 2009 improved readme [nst]
file UnitTests-Info.plist Tue Feb 24 02:47:13 -0800 2009 initial import [nst]
file UnitTests.h Tue Feb 24 02:47:13 -0800 2009 initial import [nst]
file UnitTests.m Tue Feb 24 02:47:13 -0800 2009 initial import [nst]
README
Map, filter and reduce in Objective-C/Cocoa
-------------------------------------------

This is a category to add Python like map, filter and reduce methods to Cocoa NSArray:

    @interface NSArray (Functional)
    
    - (NSArray *)filterUsingSelector:(SEL)aSelector, ...;
    - (NSArray *)mapUsingSelector:(SEL)aSelector, ...;
    - (id)reduceUsingSelector:(SEL)aSelector;
    
    @end

You can then program in functional style:

    NSArray *a = [NSArray arrayWithObjects:@"a", @"ab", @"abc", @"bc", @"c", nil];
    
    NSArray *x = [a filterUsingSelector:@selector(hasPrefix:), @"a", nil];
    NSArray *y = [a mapUsingSelector:@selector(uppercaseString), nil];
    NSArray *z = [a reduceUsingSelector:@selector(stringByAppendingString:)];

Results:

    x: (a, ab, abc)
    y: (A, AB, ABC, BC, C)
    z: aababcbcc

Read the blog post talking about it: http://seriot.ch/blog.php?article=20090109 .