Extensions
These functions are _.m-specific additions not found in Underscore.js.
isTruthy
Section titled “isTruthy”Returns YES if the value is truthy (not nil, not empty, not zero).
B result = _.isTruthy(@"hello");// => YES
B result = _.isTruthy(@"");// => NO
B result = _.isTruthy(N.I(0));// => NOisFalsy
Section titled “isFalsy”Returns YES if the value is falsy.
B result = _.isFalsy(nil);// => YES
B result = _.isFalsy(@"");// => YESisDictionary
Section titled “isDictionary”Returns YES if the value is an NSDictionary.
B result = _.isDictionary(OKV({@"a", N.I(1)}));// => YESisBlock
Section titled “isBlock”Returns YES if the value is a block.
B result = _.isBlock(^{ NSLog(@"hello"); });// => YESvalueTester
Section titled “valueTester”Creates a block that tests values against a condition.
_TestBlock isEven = _.valueTester(^B(N* num) { return num.I % 2 == 0;});
B result = isEven(N.I(4));// => YESvalueStringTester
Section titled “valueStringTester”Creates a block that tests string values.
_StringTestBlock startsWith = _.valueStringTester(^B(S* str) { return [str hasPrefix:@"foo"];});setProps
Section titled “setProps”Sets multiple properties on an object.
_.setProps(obj, OKV({@"name", @"moe"}, {@"age", N.I(50)}));classNames
Section titled “classNames”Generates a class name string from conditionals (useful for CSS classes).
S* result = _.classNames(OKV( {@"btn", @YES}, {@"btn-primary", @YES}, {@"disabled", @NO}));// => "btn btn-primary"Iterator Extensions
Section titled “Iterator Extensions”eachWithStop
Section titled “eachWithStop”Iterates with the ability to stop early.
firstIterator / lastIterator / initialIterator / restIterator
Section titled “firstIterator / lastIterator / initialIterator / restIterator”Iterator versions of array functions for lazy evaluation.
// Process items one at a time_Iterator iter = _.firstIterator(AI(1, 2, 3, 4, 5), 3);while (iter.hasNext()) { id value = iter.next(); // process value}