Arr
constArr:object
Defined in: Data/Arr.ts:1160
Type Declaration
Section titled “Type Declaration”append
Section titled “append”append: <
A>(value) => (data) =>NonEmptyArr<A>
Appends a value to the end of an array, returning a NonEmptyArr.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”(data) => NonEmptyArr<A>
Example
Section titled “Example”at: (
index) => <A>(data) =>Maybe<A>
Safely looks up an element by index. Supports negative indices counting back from the end.
Returns None if the index is out of bounds.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”<A>(data) => Maybe<A>
Example
Section titled “Example”chunkBy
Section titled “chunkBy”chunkBy: <
A,K>(keyFn) => (data) => readonly readonlyA[][]
Groups consecutive elements that share the same key returned by keyFn.
Type Parameters
Section titled “Type Parameters”A
K
Parameters
Section titled “Parameters”(a) => K
Returns
Section titled “Returns”(data) => readonly readonly A[][]
Example
Section titled “Example”chunksOf
Section titled “chunksOf”chunksOf: (
n) => <A>(data) => readonly readonlyA[][]
Splits an array into chunks of the given size.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”<A>(data) => readonly readonly A[][]
Example
Section titled “Example”compact
Section titled “compact”compact: <
A>(data) => readonlyA[]
Narrows a list of Maybe values down to a list of their underlying values, discarding all None instances.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly Maybe<A>[]
Returns
Section titled “Returns”readonly A[]
Example
Section titled “Example”concat
Section titled “concat”concat: <
A>(other) => (data) => readonlyA[]
Concatenates a standard array with another array.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”(data) => readonly A[]
Example
Section titled “Example”dedupeAdjacent
Section titled “dedupeAdjacent”dedupeAdjacent: <
A>(eq) => (data) => readonlyA[]
Removes consecutive duplicate elements.
An optional Equality<A> can be provided (defaults to Object.is).
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Equality<A> = ...
Returns
Section titled “Returns”(data) => readonly A[]
Example
Section titled “Example”drop: (
n) => <A>(data) => readonlyA[]
Drops the first n elements from an array.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”<A>(data) => readonly A[]
Example
Section titled “Example”dropWhile
Section titled “dropWhile”dropWhile: <
A>(predicate) => (data) => readonlyA[]
Drops elements from the start while the predicate holds.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(a) => boolean
Returns
Section titled “Returns”(data) => readonly A[]
Example
Section titled “Example”every: <
A>(predicate) => (data) =>boolean
Returns true if all elements satisfy the predicate.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(a) => boolean
Returns
Section titled “Returns”(data) => boolean
Example
Section titled “Example”filter
Section titled “filter”filter: <
A>(predicate) => (data) => readonlyA[]
Filters elements that satisfy the predicate.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(a) => boolean
Returns
Section titled “Returns”(data) => readonly A[]
Example
Section titled “Example”filterMap
Section titled “filterMap”filterMap: <
A,B>(f) => (data) => readonlyB[]
Maps each element to a Maybe and collects only the Some values. Combines map and filter in a single pass.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => Maybe<B>
Returns
Section titled “Returns”(data) => readonly B[]
Example
Section titled “Example”findFirst
Section titled “findFirst”findFirst: <
A>(predicate) => (data) =>Maybe<A>
Returns the first element matching the predicate, or None.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(a) => boolean
Returns
Section titled “Returns”(data) => Maybe<A>
Example
Section titled “Example”findIndex
Section titled “findIndex”findIndex: <
A>(predicate) => (data) =>Maybe<number>
Returns the index of the first element matching the predicate, or None.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(a) => boolean
Returns
Section titled “Returns”(data) => Maybe<number>
Example
Section titled “Example”findLast
Section titled “findLast”findLast: <
A>(predicate) => (data) =>Maybe<A>
Returns the last element matching the predicate, or None.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(a) => boolean
Returns
Section titled “Returns”(data) => Maybe<A>
Example
Section titled “Example”findMap
Section titled “findMap”findMap: <
A,B>(f) => (data) =>Maybe<B>
Finds the first element in an array for which f returns Some(b).
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => Maybe<B>
Returns
Section titled “Returns”(data) => Maybe<B>
Example
Section titled “Example”flatMap
Section titled “flatMap”flatMap: <
A,B>(f) => (data) => readonlyB[]
Maps each element to an array and flattens the result.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => readonly B[]
Returns
Section titled “Returns”(data) => readonly B[]
Example
Section titled “Example”flatten
Section titled “flatten”flatten: <
A>(data) => readonlyA[]
Flattens a nested array by one level.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly readonly A[][]
Returns
Section titled “Returns”readonly A[]
Example
Section titled “Example”frequencies
Section titled “frequencies”frequencies: <
A>(data) =>ReadonlyMap<A,number>
Counts occurrences of each element in an array, returning a ReadonlyMap<A, number>.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”ReadonlyMap<A, number>
Example
Section titled “Example”from:
object=ArrFrom
from.Array
Section titled “from.Array”Array: <
A>(data) =>Maybe<NonEmptyArr<A>>
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”Maybe<NonEmptyArr<A>>
groupBy
Section titled “groupBy”groupBy: <
A>(f) => (data) =>Record<string,NonEmptyArr<A>>
Groups elements by a key function.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”(a) => string
Returns
Section titled “Returns”(data) => Record<string, NonEmptyArr<A>>
Example
Section titled “Example”head: <
A>(data) =>Maybe<A>
Returns the first element of an array, or None if the array is empty.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”Maybe<A>
Example
Section titled “Example”indexBy
Section titled “indexBy”indexBy: <
A,K>(keyFn) => (data) =>ReadonlyMap<K,A>
Indexes elements of an array into a ReadonlyMap<K, A> using a key extraction function.
Type Parameters
Section titled “Type Parameters”A
K
Parameters
Section titled “Parameters”(a) => K
Returns
Section titled “Returns”(data) => ReadonlyMap<K, A>
Example
Section titled “Example”init: <
A>(data) =>Maybe<readonlyA[]>
Returns all elements except the last, or None if the array is empty.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”Maybe<readonly A[]>
Example
Section titled “Example”insertAt
Section titled “insertAt”insertAt: <
A>(index,item) => (data) => readonlyA[]
Returns a new array with item inserted before the element at index.
Negative indices are clamped to 0; indices beyond the array length append to the end.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”number
A
Returns
Section titled “Returns”(data) => readonly A[]
Example
Section titled “Example”intersperse
Section titled “intersperse”intersperse: <
A>(sep) => (data) => readonlyA[]
Inserts a separator between every element.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”(data) => readonly A[]
Example
Section titled “Example”is:
object=ArrIs
is.empty
Section titled “is.empty”empty: <
A>(data) =>data is readonly []
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”data is readonly []
is.nonEmpty
Section titled “is.nonEmpty”nonEmpty: <
A>(data) =>data is NonEmptyArr<A>
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”data is NonEmptyArr<A>
last: <
A>(data) =>Maybe<A>
Returns the last element of an array, or None if the array is empty.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”Maybe<A>
Example
Section titled “Example”map: <
A,B>(f) => (data) => readonlyB[]
Transforms each element of an array.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => B
Returns
Section titled “Returns”(data) => readonly B[]
Example
Section titled “Example”mapWithIndex
Section titled “mapWithIndex”mapWithIndex: <
A,B>(f) => (data) => readonlyB[]
Transforms each element using both its value and its zero-based index.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(i, a) => B
Returns
Section titled “Returns”(data) => readonly B[]
Example
Section titled “Example”NonEmpty
Section titled “NonEmpty”NonEmpty:
object=ArrNonEmpty
NonEmpty.concat
Section titled “NonEmpty.concat”concat: <
A>(other) => (data) =>NonEmptyArr<A>
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”(data) => NonEmptyArr<A>
NonEmpty.from
Section titled “NonEmpty.from”from:
object
NonEmpty.from.Array
Section titled “NonEmpty.from.Array”Array: <
A>(data) =>Maybe<NonEmptyArr<A>>
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”Maybe<NonEmptyArr<A>>
NonEmpty.head
Section titled “NonEmpty.head”head: <
A>(data) =>A
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”NonEmptyArr<A>
Returns
Section titled “Returns”A
NonEmpty.intersperse
Section titled “NonEmpty.intersperse”intersperse: <
A>(sep) => (data) =>NonEmptyArr<A>
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”(data) => NonEmptyArr<A>
NonEmpty.last
Section titled “NonEmpty.last”last: <
A>(data) =>A
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”NonEmptyArr<A>
Returns
Section titled “Returns”A
NonEmpty.map
Section titled “NonEmpty.map”map: <
A,B>(f) => (data) =>NonEmptyArr<B>
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => B
Returns
Section titled “Returns”(data) => NonEmptyArr<B>
NonEmpty.mapWithIndex
Section titled “NonEmpty.mapWithIndex”mapWithIndex: <
A,B>(f) => (data) =>NonEmptyArr<B>
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(i, a) => B
Returns
Section titled “Returns”(data) => NonEmptyArr<B>
NonEmpty.reduce
Section titled “NonEmpty.reduce”reduce: <
A>(f) => (data) =>A
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”(acc, a) => A
Returns
Section titled “Returns”(data) => A
NonEmpty.reverse
Section titled “NonEmpty.reverse”reverse: <
A>(data) =>NonEmptyArr<A>
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”NonEmptyArr<A>
Returns
Section titled “Returns”NonEmptyArr<A>
NonEmpty.singleton
Section titled “NonEmpty.singleton”singleton: <
A>(value) =>NonEmptyArr<A>
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”NonEmptyArr<A>
NonEmpty.tail
Section titled “NonEmpty.tail”tail: <
A>(data) => readonlyA[]
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”NonEmptyArr<A>
Returns
Section titled “Returns”readonly A[]
partition
Section titled “partition”partition: <
A>(predicate) => (data) => readonly [readonlyA[], readonlyA[]]
Splits an array into two groups based on a predicate. First group contains elements that satisfy the predicate, second group contains the rest.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(a) => boolean
Returns
Section titled “Returns”(data) => readonly [readonly A[], readonly A[]]
Example
Section titled “Example”partitionMap
Section titled “partitionMap”partitionMap: <
A,E,B>(f) => (data) => readonly [readonlyE[], readonlyB[]]
Maps each element to a Result, and separates the results into a tuple of failures and successes.
Type Parameters
Section titled “Type Parameters”A
E
B
Parameters
Section titled “Parameters”(a) => Result<E, B>
Returns
Section titled “Returns”(data) => readonly [readonly E[], readonly B[]]
Example
Section titled “Example”partitionMaybe
Section titled “partitionMaybe”partitionMaybe: <
A,B>(f) => (data) => readonly [readonlyA[], readonlyB[]]
Partitions an array by applying a function returning Maybe<B>.
Elements returning None are gathered into failures (original A values);
elements returning Some(b) are gathered into successes (B values).
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => Maybe<B>
Returns
Section titled “Returns”(data) => readonly [readonly A[], readonly B[]]
Example
Section titled “Example”prepend
Section titled “prepend”prepend: <
A>(value) => (data) =>NonEmptyArr<A>
Prepends a value to the beginning of an array, returning a NonEmptyArr.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”(data) => NonEmptyArr<A>
Example
Section titled “Example”reduce
Section titled “reduce”reduce: <
A,B>(initial,f) => (data) =>B
Reduces an array from the left.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”initial
Section titled “initial”B
(acc, a) => B
Returns
Section titled “Returns”(data) => B
Example
Section titled “Example”removeAt
Section titled “removeAt”removeAt: (
index) => <A>(data) => readonlyA[]
Returns a new array with the element at index removed.
Returns the original array unchanged if index is out of bounds.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”<A>(data) => readonly A[]
Example
Section titled “Example”reverse
Section titled “reverse”reverse: <
A>(data) => readonlyA[]
Reverses an array. Returns a new array.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”readonly A[]
Example
Section titled “Example”scan: <
A,B>(initial,f) => (data) => readonlyB[]
Like reduce, but returns every intermediate accumulator as an array.
The initial value is not included — the output has the same length as the input.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”initial
Section titled “initial”B
(acc, a) => B
Returns
Section titled “Returns”(data) => readonly B[]
Example
Section titled “Example”separate
Section titled “separate”separate: <
E,A>(data) => readonly [readonlyE[], readonlyA[]]
Separates an array of Result values into two separate lists of errors and successes.
Returns a tuple containing [errors, successes].
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”readonly Result<E, A>[]
Returns
Section titled “Returns”readonly [readonly E[], readonly A[]]
Example
Section titled “Example”sequence
Section titled “sequence”sequence:
object
sequence.Maybe
Section titled “sequence.Maybe”Maybe: <
A>(data) =>Maybe<readonlyA[]> =ArrMaybe.sequence
Collects an array of Maybe instances into a Maybe of array. Returns None if any element is None.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly Maybe<A>[]
Returns
Section titled “Returns”Maybe<readonly A[]>
Example
Section titled “Example”sequence.Result
Section titled “sequence.Result”Result: <
E,A>(data) =>Result<E, readonlyA[]> =ArrResult.sequence
Collects an array of Results into a Result of array. Returns the first Err if any element is Err.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”readonly Result<E, A>[]
Returns
Section titled “Returns”Result<E, readonly A[]>
Example
Section titled “Example”sequence.Task
Section titled “sequence.Task”Task:
TaskSequence=_sequenceTask
size: <
A>(data) =>number
Returns the length of an array.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”number
Example
Section titled “Example”some: <
A>(predicate) => (data) =>boolean
Returns true if any element satisfies the predicate.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(a) => boolean
Returns
Section titled “Returns”(data) => boolean
Example
Section titled “Example”sortBy
Section titled “sortBy”sortBy: <
A>(compare) => (data) => readonlyA[]
Sorts an array using a comparison function. Returns a new array.
To sort with a typed Ordering<A>, prefer Arr.sortWith.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”compare
Section titled “compare”(a, b) => number
Returns
Section titled “Returns”(data) => readonly A[]
Example
Section titled “Example”sortWith
Section titled “sortWith”sortWith: <
A>(ord) => (data) => readonlyA[]
Sorts an array using an Ordering<A>. Returns a new array without mutating the original.
Use this over sortBy when you have a typed Ordering<A> from the Ordering module.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Ordering<A>
Returns
Section titled “Returns”(data) => readonly A[]
Example
Section titled “Example”splitAt
Section titled “splitAt”splitAt: (
index) => <A>(data) => readonly [readonlyA[], readonlyA[]]
Splits an array at an index into a [before, after] tuple.
Negative indices clamp to 0; indices beyond the array length clamp to the end.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”<A>(data) => readonly [readonly A[], readonly A[]]
Example
Section titled “Example”tail: <
A>(data) =>Maybe<readonlyA[]>
Returns all elements except the first, or None if the array is empty.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”Maybe<readonly A[]>
Example
Section titled “Example”take: (
n) => <A>(data) => readonlyA[]
Takes the first n elements from an array.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”<A>(data) => readonly A[]
Example
Section titled “Example”takeWhile
Section titled “takeWhile”takeWhile: <
A>(predicate) => (data) => readonlyA[]
Takes elements from the start while the predicate holds.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(a) => boolean
Returns
Section titled “Returns”(data) => readonly A[]
Example
Section titled “Example”traverse
Section titled “traverse”traverse:
object
traverse.Maybe
Section titled “traverse.Maybe”Maybe: <
A,B>(f) => (data) =>Maybe<readonlyB[]> =ArrMaybe.traverse
Maps each element to a Maybe and collects the results. Returns None if any mapping returns None.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => Maybe<B>
Returns
Section titled “Returns”(data) => Maybe<readonly B[]>
Example
Section titled “Example”traverse.Result
Section titled “traverse.Result”Result: <
E,A,B>(f) => (data) =>Result<E, readonlyB[]> =ArrResult.traverse
Maps each element to a Result and collects the results. Returns the first Err if any mapping fails.
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”(a) => Result<E, B>
Returns
Section titled “Returns”(data) => Result<E, readonly B[]>
Example
Section titled “Example”traverse.Task
Section titled “traverse.Task”Task:
TaskTraverse=_traverseTask
unfold
Section titled “unfold”unfold: <
A,S>(initial,f) => readonlyA[]
Generates an array from an initial seed state until f returns None.
Type Parameters
Section titled “Type Parameters”A
S
Parameters
Section titled “Parameters”initial
Section titled “initial”S
(state) => Maybe<readonly [A, S]>
Returns
Section titled “Returns”readonly A[]
Example
Section titled “Example”uniq: <
A>(data) => readonlyA[]
Removes duplicate elements using strict equality.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”readonly A[]
Example
Section titled “Example”uniqBy
Section titled “uniqBy”uniqBy: <
A,B>(f) => (data) => readonlyA[]
Removes duplicate elements by comparing the result of a key function.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => B
Returns
Section titled “Returns”(data) => readonly A[]
Example
Section titled “Example”uniqWith
Section titled “uniqWith”uniqWith: <
A>(eq) => (data) => readonlyA[]
Removes duplicate elements using a custom equality check.
Preserves the order of first occurrences. Complements uniq (reference equality)
and uniqBy (key extraction).
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Equality<A>
Returns
Section titled “Returns”(data) => readonly A[]
Example
Section titled “Example”windowed
Section titled “windowed”windowed: (
windowSize,options?) => <A>(data) => readonly readonlyA[][]
Produces a sliding window of size elements over an array, advancing by step (default 1).
Returns an empty array if size <= 0 or size > data.length.
Parameters
Section titled “Parameters”windowSize
Section titled “windowSize”number
options?
Section titled “options?”number
Returns
Section titled “Returns”<A>(data) => readonly readonly A[][]
Example
Section titled “Example”zip: <
B>(other) => <A>(data) => readonly readonly [A,B][]
Pairs up elements from two arrays. Stops at the shorter array.
Type Parameters
Section titled “Type Parameters”B
Parameters
Section titled “Parameters”readonly B[]
Returns
Section titled “Returns”<A>(data) => readonly readonly [A, B][]
Example
Section titled “Example”zipWith
Section titled “zipWith”zipWith: <
A,B,C>(f) => (other) => (data) => readonlyC[]
Combines elements from two arrays using a function. Stops at the shorter array.
Type Parameters
Section titled “Type Parameters”A
B
C
Parameters
Section titled “Parameters”(a, b) => C
Returns
Section titled “Returns”(other) => (data) => readonly C[]