Arrays
Functions for working with arrays (NSArray).
Returns the first element(s) of an array.
N* first = _.first(AI(5, 4, 3, 2, 1));// => 5
A* firstThree = _.first(AI(5, 4, 3, 2, 1), 3);// => [5, 4, 3]Alias: head, take
initial
Section titled “initial”Returns everything but the last entry.
A* result = _.initial(AI(5, 4, 3, 2, 1));// => [5, 4, 3, 2]Returns the last element(s) of an array.
N* last = _.last(AI(5, 4, 3, 2, 1));// => 1
A* lastThree = _.last(AI(5, 4, 3, 2, 1), 3);// => [3, 2, 1]Returns everything but the first entry.
A* result = _.rest(AI(5, 4, 3, 2, 1));// => [4, 3, 2, 1]Alias: tail, drop
compact
Section titled “compact”Returns a copy with all falsy values removed.
A* result = _.compact(AA(@[@0, @1, @NO, @2, @"", @3]));// => [1, 2, 3]flatten
Section titled “flatten”Flattens a nested array.
A* result = _.flatten(AA(@[@[@1, @2], @[@3, @[@4]]]));// => [1, 2, 3, 4]without
Section titled “without”Returns a copy without the specified values.
A* result = _.without(AI(1, 2, 1, 0, 3, 1, 4), N.I(0), N.I(1));// => [2, 3, 4]Returns the union of arrays (unique values).
A* result = _.union(AI(1, 2, 3), AI(101, 2, 1, 10), AI(2, 1));// => [1, 2, 3, 101, 10]intersection
Section titled “intersection”Returns values present in all arrays.
A* result = _.intersection(AI(1, 2, 3), AI(101, 2, 1, 10), AI(2, 1));// => [1, 2]difference
Section titled “difference”Returns values from the first array not in the others.
A* result = _.difference(AI(1, 2, 3, 4, 5), AI(5, 2, 10));// => [1, 3, 4]Returns a duplicate-free version.
A* result = _.uniq(AI(1, 2, 1, 3, 1, 4));// => [1, 2, 3, 4]Alias: unique
Merges arrays by index position.
A* result = _.zip(AA(@[@"moe", @"larry", @"curly"]), AI(30, 40, 50), AA(@[@YES, @NO, @NO]));// => [["moe", 30, YES], ["larry", 40, NO], ["curly", 50, NO]]zipObject
Section titled “zipObject”Creates an object from arrays of keys and values.
O* result = _.zipObject(AA(@[@"moe", @"larry", @"curly"]), AI(30, 40, 50));// => {moe: 30, larry: 40, curly: 50}indexOf
Section titled “indexOf”Returns the index of the first occurrence.
I index = _.indexOf(AI(1, 2, 3), N.I(2));// => 1lastIndexOf
Section titled “lastIndexOf”Returns the index of the last occurrence.
I index = _.lastIndexOf(AI(1, 2, 3, 1, 2, 3), N.I(2));// => 4Generates a range of integers.
A* result = _.range(10);// => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
A* result = _.range(1, 11);// => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
A* result = _.range(0, 30, 5);// => [0, 5, 10, 15, 20, 25]