MODULE Array
function
<A>(as: Array<Option<A>>): Array<A>
Filter an array of optional values, keeping only the elements which contain a value, creating a new array
function
<A>(as: Array<A>): Array<A>
function
<A>(i: number, as: Array<A>): Option<Array<A>>
Delete the element at the specified index, creating a new array, or returning None
if the index is out of bounds
function
<A>(n: number, as: Array<A>): Array<A>
Drop a number of elements from the start of an array, creating a new array
function
<A>(as: Array<A>, predicate: Predicate<A>): Array<A>
Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new array
function
<A>(as: Array<A>, predicate: Predicate<A>): Array<A>
Filter an array, keeping the elements which satisfy a predicate function, creating a new array
function
<A>(as: Array<A>, predicate: Predicate<A>): Option<A>
Find the first element which satisfies a predicate function
function
<A>(as: Array<A>, predicate: Predicate<A>): Option<number>
Find the first index for which a predicate holds
function
<A>(as: Array<A>, predicate: Predicate<A>): Option<A>
Find the last element which satisfies a predicate function
function
<A>(ffa: Array<Array<A>>): Array<A>
Example
flatten([[1], [2], [3]]) // [1, 2, 3]
function
<A, B>(as: Array<A>, b: B, cons: (head: A, tail: Array<A>) => B): B
Break an array into its first element and remaining elements
function
<A, B>(as: Array<A>, nil: () => B, cons: (head: A, tail: Array<A>) => B): B
Lazy version of fold
function
<A = never>(): Monoid<Array<A>>
function
<A>(as: Array<A>): Option<A>
Get the first element in an array, or None
if the array is empty
function
<A>(i: number, as: Array<A>): Option<A>
This function provides a safe way to read a value at a particular index from an array
function
<A>(as: Array<A>): Option<Array<A>>
Get all but the last element of an array, creating a new array, or None
if the array is empty
function
<A>(i: number, a: A, as: Array<A>): Option<Array<A>>
Insert an element at the specified index, creating a new array, or returning None
if the index is out of bounds
function
<A>(as: Array<A>): boolean
Test whether an array is empty
function
<A>(i: number, as: Array<A>): boolean
Test whether an array contains a particular index
function
<A>(as: Array<A>): Option<A>
Get the last element in an array, or None
if the array is empty
function
<L, A>(as: Array<Either<L, A>>): Array<L>
Extracts from a list of Either
all the Left
elements. All the Left
elements are extracted in order
function
<A, B>(as: Array<A>, f: (a: A) => Option<B>): Array<B>
Apply a function to each element in an array, keeping only the results which contain a value, creating a new array
function
<A>(as: Array<A>, i: number, f: Endomorphism<A>): Option<Array<A>>
Apply a function to the element at the specified index, creating a new array, or returning None
if the index is out of
bounds
function
<A, L, R>(fa: Array<A>, f: (a: A) => Either<L, R>): { left: Array<L>; right: Array<R> }
function
<A, B extends A>(as: Array<A>, refinement: Refinement<A, B>): Array<B>
function
<A>(as: Array<A>): Array<A>
Reverse an array, creating a new array
function
<L, A>(as: Array<Either<L, A>>): Array<A>
Extracts from a list of Either
all the Right
elements. All the Right
elements are extracted in order
function
<A>(n: number, xs: Array<A>): Array<A>
Rotate an array to the right by n
steps
function
<A, B>(as: Array<A>, b: B, f: ((b: B, a: A) => B)): Array<B>
Same as reduce
but it carries over the intermediate steps
scanLeft([1, 2, 3], 10, (b, a) => b - a) // [ 10, 9, 7, 4 ]
function
<A, B>(as: Array<A>, b: B, f: (a: A, b: B) => B): Array<B>
Fold an array from the right, keeping all intermediate results instead of only the final result
scanRight([1, 2, 3], 10, (a, b) => b - a) // [ 4, 5, 7, 10 ]
function
<A>(as: Array<A>, a: A): Array<A>
Append an element to the end of an array, creating a new array
function
<A>(ord: Ord<A>): ((as: Array<A>) => Array<A>)
Sort the elements of an array in increasing order, creating a new array
function
<A>(as: Array<A>, predicate: Predicate<A>): { init: Array<A>; rest: Array<A> }
Split an array into two parts:
- the longest initial subarray for which all elements satisfy the specified predicate
- the remaining elements
function
<A>(as: Array<A>): Option<Array<A>>
Get all but the first element of an array, creating a new array, or None
if the array is empty
function
<A>(n: number, as: Array<A>): Array<A>
Keep only a number of elements from the start of an array, creating a new array
function
<A>(as: Array<A>, predicate: Predicate<A>): Array<A>
Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new array
function
<A>(i: number, as: Array<A>): Array<A>
function
<A>(i: number, a: A, as: Array<A>): Array<A>
function
<A>(i: number, a: A, as: Array<A>): Array<A>
function
<A>(i: number, a: A, as: Array<A>): Option<Array<A>>
Change the element at the specified index, creating a new array, or returning None
if the index is out of bounds
function
<A, B>(fa: Array<A>, fb: Array<B>): Array<[A, B]>
Takes two arrays and returns an array of corresponding pairs. If one input array is short, excess elements of the longer array are discarded
function
<A, B, C>(fa: Array<A>, fb: Array<B>, f: (a: A, b: B) => C): Array<C>
Apply a function to pairs of elements at the same index in two arrays, collecting the results in a new array. If one input array is short, excess elements of the longer array are discarded.