xtr.arrays¶
all¶
all(value: Array[A], func: Func[(A) => Boolean]): Boolean
Returns true if all elements in value satisfy the given func, otherwise false. func must accept an A.
Example
Resultany¶
any(value: Array[A], func: Func[(A) => Boolean]): Boolean
Returns true if any element in value satisfies the given func, otherwise false. func must accept an A.
Example
Resultbreak¶
break(arr: Array[A], func: Func[(A) => Boolean]): Object[Array[A]]
Returns an Object with two entries:
leftkey with anArray[A]containing the elements ofarrbefore the first element to satisfy the givenfunc.rightkey with anArray[A]containing the remaining elements ofarr.
Example
ResultchunksOf¶
chunksOf(array: Array[A], size: Number): Array[Array[A]]
Returns a new Array of Array[A], with every element containing the next size elements in array.
Example
ResultcountBy¶
countBy(arr: Array[A], func: Func[(A) => Boolean]): Number
Returns a Number count of all the elements in arr that satisfy the given func, which must accept an A.
Example
ResultdistinctBy¶
distinctBy func(value)¶
distinctBy(container: Array[A], func: Func[(A) => B]): Array[A]
Returns a new Array with the distinct elements in container using the given func function for comparison. func must accept an A.
Example
ResultThe modulo operation on the elements yields [1, 2, 0, 1, 2, 0] meaning 1 and 4 share the same identity, therefore 1 is kept and 4 discarded. Same is true for 2 and 3 with 5 and 6, respectively.
distinctBy func(value, idx)¶
distinctBy(container: Array[A], func: Func[(A, Number) => B]): Array[A]
Returns a new Array with the distinct elements in container using the given func function for comparison. func must accept an A and its Number index.
Example
ResultThe computation on the elements yields [1, 0, 2, 1, 0, 2], meaning 4, 5, and 6 share an identity with 1, 2, and 3 respectively, so they are discarded.
drop¶
drop(arr: Array[A], num: Number): Array[A]
Returns a new Array with the elements in arr but dropping the first num elements.
Example
ResultdropWhile¶
dropWhile(arr: Array[A], func: Func[(A) => Boolean]): Array[A]
Returns a new Array with the elements in arr, but dropping the first elements while they satisfy the given func, which must accept an A.
Example
ResultduplicatesBy¶
duplicatesBy(array: Array[A], func: Func[(A) => B]): Array[A]
Returns a new Array with the elements in array whose identity, as computed by func, is shared by more than one element. Each duplicated identity contributes the first element that produced it, in the order they appear in array.
Example
ResultExample
xtr.arrays.duplicatesBy([{ id: 1, n: 'a' }, { id: 2, n: 'c' }, { id: 1, n: 'b' }], function(item) item.id)
find¶
find func(value)¶
find(arr: Array[A], func: Func[(A) => Boolean]): Array[A]
Returns a single element Array with the first A that satisfies the given func, which must accept an A.
Example
Resultfind func(value, idx)¶
find(arr: Array[A], func: Func[(A, Number) => Boolean]): Array[A]
Returns a single element Array with the first A that satisfies the given func, which must accept an A and its Number index.
Example
Resultflat¶
flat(arr: Array[Any]): Array[Any]
Returns a new single level Array with the contents of all Array in arr, recursively flattening each Array element found.
Example
ResultindexWhere¶
indexWhere(arr: Array[A], func: Func[(A) => Boolean]): Number
Returns the Number index of the first element that satisfies the given func, otherwise -1. func must accept an A.
Example
ResultindicesWhere¶
indicesWhere(arr: Array[A], func: Func[(A) => Boolean]): Array[Number]
Returns an Array[Number] with the indices of elements that satisfy the given func, which must accept exactly one parameter, an A.
Example
ResultlastIndexWhere¶
lastIndexWhere(arr: Array[A], func: Func[(A) => Boolean]): Number
Returns the Number index of the last element in arr that satisfies the given func, otherwise -1. func must accept an A.
Example
ResultoccurrencesBy¶
occurrencesBy(arr: Array[A], func: Func[(A) => String|Number|Boolean|Null]): Object[Number]
Returns an Object with an entry for each unique identity of elements in arr. The value of each entry is the Number of elements in arr that produced such identity, using func, which must take an A. Entries appear in the order their identity was first produced.
Example
Resultpartition¶
partition(arr: Array[A], func: Func[(A) => Boolean]): Object[Array[A]]
Returns an Object with two entries:
passkey with anArray[A]of the subset of elements inarrthat satisfy the givenfunc, which must take anA.failkey with anArray[A]of the subset of elements inarrthat fail the givenfunc, which must take anA.
Example
ResultsplitAt¶
splitAt(array: Array[A], index: Number): Object[Array[A]]
Returns an Object with two entries:
leftkey with anArray[A]containing the elements ofarraybefore theindexelement.rightkey with anArray[A]containing the remaining elements ofarray.
Example
ResultsumBy¶
sumBy(array: Array[A], func: Func[(A) => Number]): Number
Returns the Number sum of the values obtained by applying the given func to every element in array. func must accept an A and return a Number.
Example
Resulttake¶
take(array: Array[A], index: Number): Array[A]
Returns a new Array with the elements in array, but only taking the first index elements.
Example
ResulttakeWhile¶
takeWhile(array: Array[A], func: Func[(A) => Boolean]): Array[A]
Returns a new Array with the elements in array, but only taking the first elements that satisfy the given func, which must accept an A.
Example
Resultunzip¶
unzip(array: Array[Array[A]]): Array[Array[A]]
Create n-number of Arrays, each containing the n-th element of every array in array.
Returns a new Array of equal size to the shortest array in array. Every n-th element in the result is an Array containing the n-th element of the arrays in array.
Example
ResultunzipAll¶
unzipAll(array: Array[Array[A]], fill: B): Array[Array[A|B]]
Create n-number of Arrays, each containing the n-th element of every array in arr, using a fill value for missing n-th elements.
Returns a new Array of equal size to the longest array in arr. Every n-th element in the result is an Array containing the n-th element of the arrays in arr that have such element, or fill for short arrays.
Example
Resultzip¶
zip(arr1: Array[A], arr2: Array[B], arr3: Array[C], arr4: Array[D], arr5: Array[E]): Array[Array[A|B|C|D|E]]
Combines corresponding elements of the given arrays. Accepts two to five arrays; arr3 through arr5 are optional.
Returns a new Array of equal size to the shortest array given. Every n-th element in the result is an Array containing the n-th element of the given arrays.
Example
ResultzipAll¶
zipAll(array: Array[Array[A]], fill: B): Array[Array[A|B]]
Combines corresponding elements of the arrays in arr, using a fill value for short arrays.
Returns a new Array of equal size to the longest array in arr. Every n-th element in the result is an Array containing the n-th element of the arrays in arr that have such element, or fill for short arrays.
Example
Result