Skip to content

Extensions

These functions are _.m-specific additions not found in Underscore.js.

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));
// => NO

Returns YES if the value is falsy.

B result = _.isFalsy(nil);
// => YES
B result = _.isFalsy(@"");
// => YES

Returns YES if the value is an NSDictionary.

B result = _.isDictionary(OKV({@"a", N.I(1)}));
// => YES

Returns YES if the value is a block.

B result = _.isBlock(^{ NSLog(@"hello"); });
// => YES

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));
// => YES

Creates a block that tests string values.

_StringTestBlock startsWith = _.valueStringTester(^B(S* str) {
return [str hasPrefix:@"foo"];
});

Sets multiple properties on an object.

_.setProps(obj, OKV({@"name", @"moe"}, {@"age", N.I(50)}));

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"

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
}