Introduction
_.m is a port of Underscore.js to Objective-C. It provides functional programming helpers without extending any built-in objects.
_.m uses SubjectiveScript.m to bring JavaScript-like syntax and features into Objective-C.
Features
Section titled “Features”- Collection Functions:
each,map,reduce,filter,find, and more - Array Functions:
first,last,flatten,union,intersection, etc. - Function Functions:
memoize,delay,throttle,debounce,once - Object Functions:
keys,values,extend,clone,isEqual - Utility Functions:
identity,times,uniqueId - Chaining: Fluent API with
chain()andvalue()
Quick Example
Section titled “Quick Example”#import "_.h"
// Each_.each(AI(1, 2, 3), ^(N* num, ...) { NSLog(@"%@", num);});
// MapA* doubled = _.map(AI(1, 2, 3), ^id(N* num, ...) { return N.I(num.I * 2);});// => [2, 4, 6]
// FilterA* evens = _.filter(AI(1, 2, 3, 4, 5, 6), ^B(N* num, ...) { return num.I % 2 == 0;});// => [2, 4, 6]Type Shortcuts
Section titled “Type Shortcuts”_.m uses shorthand type definitions for cleaner code:
| Shorthand | Full Type |
|---|---|
A* | NSArray* |
NSA* | NSMutableArray* |
O* | NSDictionary* |
NSD* | NSMutableDictionary* |
S* | NSString* |
NSS* | NSMutableString* |
N* | NSNumber* |
NSO* | NSObject* |
B | BOOL |
I | NSInteger |
UI | NSUInteger |
F | float |
D | double |