Skip to content

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.

  • 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() and value()
#import "_.h"
// Each
_.each(AI(1, 2, 3), ^(N* num, ...) {
NSLog(@"%@", num);
});
// Map
A* doubled = _.map(AI(1, 2, 3), ^id(N* num, ...) {
return N.I(num.I * 2);
});
// => [2, 4, 6]
// Filter
A* evens = _.filter(AI(1, 2, 3, 4, 5, 6), ^B(N* num, ...) {
return num.I % 2 == 0;
});
// => [2, 4, 6]

_.m uses shorthand type definitions for cleaner code:

ShorthandFull Type
A*NSArray*
NSA*NSMutableArray*
O*NSDictionary*
NSD*NSMutableDictionary*
S*NSString*
NSS*NSMutableString*
N*NSNumber*
NSO*NSObject*
BBOOL
INSInteger
UINSUInteger
Ffloat
Ddouble