nst / nsarray-functional
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
| name | age | message | |
|---|---|---|---|
| |
Functional.1 | Tue Feb 24 02:47:13 -0800 2009 | |
| |
Functional.m | Tue Feb 24 02:47:13 -0800 2009 | |
| |
Functional.xcodeproj/ | Tue Feb 24 02:47:13 -0800 2009 | |
| |
Functional_Prefix.pch | Tue Feb 24 02:47:13 -0800 2009 | |
| |
NSArray+Functional.h | Tue Feb 24 02:47:13 -0800 2009 | |
| |
NSArray+Functional.m | Tue Feb 24 02:47:13 -0800 2009 | |
| |
NSInvocation+Functional.h | Tue Feb 24 02:47:13 -0800 2009 | |
| |
NSInvocation+Functional.m | Tue Feb 24 02:47:13 -0800 2009 | |
| |
NSString+Cat.h | Tue Feb 24 02:47:13 -0800 2009 | |
| |
NSString+Cat.m | Tue Feb 24 02:47:13 -0800 2009 | |
| |
README | Mon Sep 28 13:06:14 -0700 2009 | |
| |
UnitTests-Info.plist | Tue Feb 24 02:47:13 -0800 2009 | |
| |
UnitTests.h | Tue Feb 24 02:47:13 -0800 2009 | |
| |
UnitTests.m | Tue Feb 24 02:47:13 -0800 2009 |
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 .
