Skip to content

Objects

Functions for working with dictionaries (NSDictionary).

Returns all keys of a dictionary.

A* result = _.keys(OKV({@"one", N.I(1)}, {@"two", N.I(2)}, {@"three", N.I(3)}));
// => ["one", "two", "three"]

Returns all values of a dictionary.

A* result = _.values(OKV({@"one", N.I(1)}, {@"two", N.I(2)}, {@"three", N.I(3)}));
// => [1, 2, 3]

Returns a sorted list of method names.

A* result = _.functions(_);
// => ["all", "any", "bind", ...]

Alias: methods

Copies all properties from source objects to the destination.

O* result = _.extend(OKV({@"name", @"moe"}), OKV({@"age", N.I(50)}));
// => {name: "moe", age: 50}

Returns a copy with only the specified keys.

O* result = _.pick(OKV({@"name", @"moe"}, {@"age", N.I(50)}, {@"userid", @"moe1"}), @"name", @"age");
// => {name: "moe", age: 50}

Fills in missing properties with default values.

O* iceCream = OKV({@"flavor", @"chocolate"});
O* result = _.defaults(iceCream, OKV({@"flavor", @"vanilla"}, {@"sprinkles", @"lots"}));
// => {flavor: "chocolate", sprinkles: "lots"}

Creates a shallow copy.

O* clone = _.clone(OKV({@"name", @"moe"}));

Invokes a block with the object, then returns the object.

O* result = _.chain(OKV({@"a", N.I(1)}))
.tap(^(O* obj) { NSLog(@"%@", obj); })
.value();

Returns YES if the key is present.

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

Performs deep comparison.

O* stooge = OKV({@"name", @"moe"}, {@"luckyNumbers", AI(13, 27, 34)});
O* clone = OKV({@"name", @"moe"}, {@"luckyNumbers", AI(13, 27, 34)});
B result = _.isEqual(stooge, clone);
// => YES

Returns YES if the object contains no values.

B result = _.isEmpty(AI());
// => YES

Returns YES if the object is an array.

B result = _.isArray(AI(1, 2, 3));
// => YES

Returns YES if the object is a dictionary.

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

Returns YES if the object is a string.

B result = _.isString(@"moe");
// => YES

Returns YES if the object is a number.

B result = _.isNumber(N.I(8) * N.I(4) / N.I(2));
// => YES

Returns YES if the object is a boolean.

B result = _.isBoolean(nil);
// => NO

Returns YES if the object is a date.

B result = _.isDate([NSDate date]);
// => YES

Returns YES if the object is NaN.

B result = _.isNaN(NAN);
// => YES

Returns YES if the object is nil.

B result = _.isNull(nil);
// => YES

Returns YES if the object is a block.

B result = _.isFunction(^{ return @"hi"; });
// => YES

Returns YES if the number is finite.

B result = _.isFinite(N.I(100));
// => YES

Returns YES if the object is an arguments array.

B result = _.isArguments(args);
// => YES

These functions are specific to _.m:

Returns YES for non-nil, non-empty values.

B result = _.isTruthy(@"hello");
// => YES

Returns YES for nil or empty values.

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(^{ });
// => YES

Creates a predicate that tests a property value.

_ItemTestBlock tester = _.valueTester(@"name", @"moe");
B result = tester(OKV({@"name", @"moe"}));
// => YES

Creates a predicate that tests a string property.

_ItemTestBlock tester = _.valueStringTester(@"name", @"moe");

Sets a property on all elements in an array.

_.setProps(items, @"selected", @YES);

Returns an array of class names for an object’s class hierarchy.

A* names = _.classNames(myObject);
// => ["MyClass", "MySuperClass", "NSObject"]