Arr
constArr:object
Defined in: Data/Arr.ts:1290
Type Declaration
Section titled “Type Declaration”append
Section titled “append”append: <
A>(item) => (items) =>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”(items) => NonEmptyArr<A>
prepend for adding an element to the beginning.
Example
Section titled “Example”at: (
index) => <A>(items) =>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>(items) => Maybe<A>
Example
Section titled “Example”chunkBy
Section titled “chunkBy”chunkBy: <
A,K>(keySelector) => (items) => readonly (readonlyA[])[]
Groups consecutive elements that share the same key returned by keySelector.
Type Parameters
Section titled “Type Parameters”A
K
Parameters
Section titled “Parameters”keySelector
Section titled “keySelector”(item) => K
Returns
Section titled “Returns”(items) => readonly (readonly A[])[]
chunksOf for fixed-size chunking.
Example
Section titled “Example”chunksOf
Section titled “chunksOf”chunksOf: (
size) => <A>(items) => readonly (readonlyA[])[]
Splits an array into chunks of the given size.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”<A>(items) => readonly (readonly A[])[]
chunkBy for grouping consecutive elements sharing a key.
Example
Section titled “Example”compact
Section titled “compact”compact: <
A>(items) => 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[]
separate for dividing Results into error and success arrays.
Example
Section titled “Example”concat
Section titled “concat”concat: <
A>(other) => (items) => 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”(items) => readonly A[]
Example
Section titled “Example”dedupeAdjacent
Section titled “dedupeAdjacent”dedupeAdjacent: <
A>(areEqual) => (items) => 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”areEqual?
Section titled “areEqual?”Equality<A> = ...
Returns
Section titled “Returns”(items) => readonly A[]
uniq for deduplicating across the entire array.
Example
Section titled “Example”drop: (
count) => <A>(items) => readonlyA[]
Drops the first n elements from an array.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”<A>(items) => readonly A[]
Example
Section titled “Example”dropWhile
Section titled “dropWhile”dropWhile: <
A>(predicate) => (items) => 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”(item) => boolean
Returns
Section titled “Returns”(items) => readonly A[]
- takeWhile for keeping elements while a predicate holds.
- drop for discarding a fixed count of elements.
Example
Section titled “Example”every: <
A>(predicate) => (items) =>boolean
Returns true if all elements satisfy the predicate.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(item) => boolean
Returns
Section titled “Returns”(items) => boolean
some for checking whether any element satisfies a predicate.
Example
Section titled “Example”filter
Section titled “filter”filter: {<
A,B>(predicate): (items) => readonlyB[]; <A>(predicate): (items) => readonlyA[]; }
Call Signature
Section titled “Call Signature”<
A,B>(predicate): (items) => readonlyB[]
Filters elements that satisfy the predicate.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(item) => item is B
Returns
Section titled “Returns”(items) => readonly B[]
filterMap for filtering and mapping simultaneously.
Example
Section titled “Example”Call Signature
Section titled “Call Signature”<
A>(predicate): (items) => readonlyA[]
Filters elements that satisfy the predicate.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(item) => boolean
Returns
Section titled “Returns”(items) => readonly A[]
filterMap for filtering and mapping simultaneously.
Example
Section titled “Example”filterMap
Section titled “filterMap”filterMap: <
A,B>(transform) => (items) => 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”transform
Section titled “transform”(item) => Maybe<B>
Returns
Section titled “Returns”(items) => readonly B[]
filter for filtering with a boolean predicate.
Example
Section titled “Example”findFirst
Section titled “findFirst”findFirst: {<
A,B>(predicate): (items) =>Maybe<B>; <A>(predicate): (items) =>Maybe<A>; }
Call Signature
Section titled “Call Signature”<
A,B>(predicate): (items) =>Maybe<B>
Returns the first element matching the predicate, or None.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(item) => item is B
Returns
Section titled “Returns”(items) => Maybe<B>
- findLast for finding the last matching element.
- findIndex for obtaining the index of the first matching element.
Example
Section titled “Example”Call Signature
Section titled “Call Signature”<
A>(predicate): (items) =>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”(item) => boolean
Returns
Section titled “Returns”(items) => Maybe<A>
- findLast for finding the last matching element.
- findIndex for obtaining the index of the first matching element.
Example
Section titled “Example”findIndex
Section titled “findIndex”findIndex: <
A>(predicate) => (items) =>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”(item) => boolean
Returns
Section titled “Returns”(items) => Maybe<number>
findFirst for finding the matching element value.
Example
Section titled “Example”findLast
Section titled “findLast”findLast: {<
A,B>(predicate): (items) =>Maybe<B>; <A>(predicate): (items) =>Maybe<A>; }
Call Signature
Section titled “Call Signature”<
A,B>(predicate): (items) =>Maybe<B>
Returns the last element matching the predicate, or None.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(item) => item is B
Returns
Section titled “Returns”(items) => Maybe<B>
findFirst for finding the first matching element.
Example
Section titled “Example”Call Signature
Section titled “Call Signature”<
A>(predicate): (items) =>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”(item) => boolean
Returns
Section titled “Returns”(items) => Maybe<A>
findFirst for finding the first matching element.
Example
Section titled “Example”findMap
Section titled “findMap”findMap: <
A,B>(transform) => (items) =>Maybe<B>
Finds the first element in an array for which transform returns Some(b).
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(item) => Maybe<B>
Returns
Section titled “Returns”(items) => Maybe<B>
findFirst for finding elements with a boolean predicate.
Example
Section titled “Example”flatMap
Section titled “flatMap”flatMap: <
A,B>(transform) => (items) => readonlyB[]
Maps each element to an array and flattens the result.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(item) => readonly B[]
Returns
Section titled “Returns”(items) => readonly B[]
Example
Section titled “Example”flatten
Section titled “flatten”flatten: <
A>(items) => 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[]
flatMap for mapping elements to arrays before flattening.
Example
Section titled “Example”frequencies
Section titled “frequencies”frequencies: <
A>(items) =>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”groupBy
Section titled “groupBy”groupBy: <
A>(keySelector) => (items) =>Record<string,NonEmptyArr<A>>
Groups elements by a key function.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”keySelector
Section titled “keySelector”(item) => string
Returns
Section titled “Returns”(items) => Record<string, NonEmptyArr<A>>
indexBy for indexing elements into a Map.
Example
Section titled “Example”head: <
A>(items) =>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>(keySelector) => (items) =>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”keySelector
Section titled “keySelector”(item) => K
Returns
Section titled “Returns”(items) => ReadonlyMap<K, A>
groupBy for grouping multiple items per key into arrays.
Example
Section titled “Example”init: <
A>(items) =>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[]>
last for accessing the final element.
Example
Section titled “Example”insertAt
Section titled “insertAt”insertAt: <
A>(index,item) => (items) => 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”(items) => readonly A[]
removeAt for removing an element at an index.
Example
Section titled “Example”intersperse
Section titled “intersperse”intersperse: <
A>(separator) => (items) => readonlyA[]
Inserts a separator between every element.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”separator
Section titled “separator”A
Returns
Section titled “Returns”(items) => readonly A[]
Example
Section titled “Example”is:
object=ArrIs
is.empty
Section titled “is.empty”empty: <
A>(items) =>boolean
Returns true when the array is empty.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”boolean
nonEmpty for checking if an array contains elements.
is.nonEmpty
Section titled “is.nonEmpty”nonEmpty: <
A>(items) =>items is NonEmptyArr<A>
Returns true when the array contains at least one element.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”items is NonEmptyArr<A>
empty for checking if an array is empty.
last: <
A>(items) =>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>(transform) => (items) => readonlyB[]
Transforms each element of an array.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(item) => B
Returns
Section titled “Returns”(items) => readonly B[]
- flatMap for mapping and flattening arrays.
- mapWithIndex for mapping with element indices.
Example
Section titled “Example”mapWithIndex
Section titled “mapWithIndex”mapWithIndex: <
A,B>(transform) => (items) => 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”transform
Section titled “transform”(index, item) => B
Returns
Section titled “Returns”(items) => readonly B[]
map for mapping without indices.
Example
Section titled “Example”NonEmpty
Section titled “NonEmpty”NonEmpty:
object=ArrNonEmpty
Utilities for working with guaranteed non-empty arrays (NonEmptyArr).
NonEmpty.concat
Section titled “NonEmpty.concat”concat: <
A>(other) => (items) =>NonEmptyArr<A>
Concatenates a non-empty array with another array, preserving non-emptiness.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”(items) => NonEmptyArr<A>
Example
Section titled “Example”NonEmpty.from
Section titled “NonEmpty.from”from:
object
NonEmpty.from.array
Section titled “NonEmpty.from.array”array: <
A>(items) =>Maybe<NonEmptyArr<A>>
Refines a standard array to a NonEmptyArr, returning Some if length > 0, None otherwise.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”Maybe<NonEmptyArr<A>>
Example
Section titled “Example”NonEmpty.head
Section titled “NonEmpty.head”head: <
A>(items) =>A
Returns the first element of a non-empty array without wrapping in Maybe.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”NonEmptyArr<A>
Returns
Section titled “Returns”A
last for accessing the last element.
Example
Section titled “Example”NonEmpty.intersperse
Section titled “NonEmpty.intersperse”intersperse: <
A>(separator) => (items) =>NonEmptyArr<A>
Inserts a separator between every element, preserving non-emptiness.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”separator
Section titled “separator”A
Returns
Section titled “Returns”(items) => NonEmptyArr<A>
Example
Section titled “Example”NonEmpty.last
Section titled “NonEmpty.last”last: <
A>(items) =>A
Returns the last element of a non-empty array without wrapping in Maybe.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”NonEmptyArr<A>
Returns
Section titled “Returns”A
head for accessing the first element.
Example
Section titled “Example”NonEmpty.map
Section titled “NonEmpty.map”map: <
A,B>(transform) => (items) =>NonEmptyArr<B>
Transforms each element of a non-empty array, preserving non-emptiness.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(item) => B
Returns
Section titled “Returns”(items) => NonEmptyArr<B>
Example
Section titled “Example”NonEmpty.mapWithIndex
Section titled “NonEmpty.mapWithIndex”mapWithIndex: <
A,B>(transform) => (items) =>NonEmptyArr<B>
Transforms each element with its index, preserving non-emptiness.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(index, item) => B
Returns
Section titled “Returns”(items) => NonEmptyArr<B>
Example
Section titled “Example”NonEmpty.reduce
Section titled “NonEmpty.reduce”reduce: <
A>(reducer) => (items) =>A
Reduces a non-empty array using its first element as the initial accumulator.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”reducer
Section titled “reducer”(accumulator, item) => A
Returns
Section titled “Returns”(items) => A
Example
Section titled “Example”NonEmpty.reverse
Section titled “NonEmpty.reverse”reverse: <
A>(items) =>NonEmptyArr<A>
Reverses a non-empty array, preserving non-emptiness.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”NonEmptyArr<A>
Returns
Section titled “Returns”NonEmptyArr<A>
Example
Section titled “Example”NonEmpty.singleton
Section titled “NonEmpty.singleton”singleton: <
A>(item) =>NonEmptyArr<A>
Creates a NonEmptyArr containing a single element.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”NonEmptyArr<A>
Example
Section titled “Example”NonEmpty.tail
Section titled “NonEmpty.tail”tail: <
A>(items) => readonlyA[]
Returns all elements except the first.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”NonEmptyArr<A>
Returns
Section titled “Returns”readonly A[]
Example
Section titled “Example”partition
Section titled “partition”partition: {<
A,B>(predicate): (items) => readonly [readonlyB[], readonlyExclude<A,B>[]]; <A>(predicate): (items) => readonly [readonlyA[], readonlyA[]]; }
Call Signature
Section titled “Call Signature”<
A,B>(predicate): (items) => readonly [readonlyB[], readonlyExclude<A,B>[]]
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
B
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(item) => item is B
Returns
Section titled “Returns”(items) => readonly [readonly B[], readonly Exclude<A, B>[]]
partitionMap for partitioning with a Result function.
Example
Section titled “Example”Call Signature
Section titled “Call Signature”<
A>(predicate): (items) => 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”(item) => boolean
Returns
Section titled “Returns”(items) => readonly [readonly A[], readonly A[]]
partitionMap for partitioning with a Result function.
Example
Section titled “Example”partitionMap
Section titled “partitionMap”partitionMap: <
A,E,B>(transform) => (items) => 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”transform
Section titled “transform”(item) => Result<E, B>
Returns
Section titled “Returns”(items) => readonly [readonly E[], readonly B[]]
- partition for partitioning with a boolean predicate.
- partitionMaybe for partitioning with a Maybe function.
Example
Section titled “Example”partitionMaybe
Section titled “partitionMaybe”partitionMaybe: <
A,B>(transform) => (items) => 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”transform
Section titled “transform”(item) => Maybe<B>
Returns
Section titled “Returns”(items) => readonly [readonly A[], readonly B[]]
- partitionMap for partitioning with a Result mapper.
- partition for partitioning with a boolean predicate.
Example
Section titled “Example”prepend
Section titled “prepend”prepend: <
A>(item) => (items) =>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”(items) => NonEmptyArr<A>
append for adding an element to the end.
Example
Section titled “Example”reduce
Section titled “reduce”reduce: <
A,B>(initial,reducer) => (items) =>B
Reduces an array from the left.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”initial
Section titled “initial”B
reducer
Section titled “reducer”(accumulator, item) => B
Returns
Section titled “Returns”(items) => B
scan for preserving intermediate accumulation states.
Example
Section titled “Example”removeAt
Section titled “removeAt”removeAt: (
index) => <A>(items) => 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>(items) => readonly A[]
insertAt for inserting an element at an index.
Example
Section titled “Example”reverse
Section titled “reverse”reverse: <
A>(items) => 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,reducer) => (items) => 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
reducer
Section titled “reducer”(accumulator, item) => B
Returns
Section titled “Returns”(items) => readonly B[]
reduce for computing only the final accumulator value.
Example
Section titled “Example”separate
Section titled “separate”separate: <
E,A>(items) => 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[]]
compact for extracting Some values from Maybe instances.
Example
Section titled “Example”sequence
Section titled “sequence”sequence:
object
Sequences an array of effectful containers into a container of array.
sequence.Maybe
Section titled “sequence.Maybe”Maybe: <
A>(items) =>Maybe<readonlyA[]> =sequenceMaybe
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly Maybe<A>[]
Returns
Section titled “Returns”Maybe<readonly A[]>
sequence.Result
Section titled “sequence.Result”Result: <
E,A>(items) =>Result<E, readonlyA[]> =sequenceResult
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”readonly Result<E, A>[]
Returns
Section titled “Returns”Result<E, readonly A[]>
sequence.Task
Section titled “sequence.Task”Task: <
A>(items) =>Task<readonlyA[]> =sequenceTask
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly Task<A>[]
Returns
Section titled “Returns”Task<readonly A[]>
sequence.Validation
Section titled “sequence.Validation”Validation: <
E,A>(items) =>Validation<E, readonlyA[]> =sequenceValidation
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”readonly Validation<E, A>[]
Returns
Section titled “Returns”Validation<E, readonly A[]>
size: <
A>(items) =>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) => (items) =>boolean
Returns true if any element satisfies the predicate.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(item) => boolean
Returns
Section titled “Returns”(items) => boolean
every for checking whether all elements satisfy a predicate.
Example
Section titled “Example”sortBy
Section titled “sortBy”sortBy: <
A>(compare) => (items) => 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”(first, second) => number
Returns
Section titled “Returns”(items) => readonly A[]
sortWith for sorting using typed Ordering instances.
Example
Section titled “Example”sortWith
Section titled “sortWith”sortWith: <
A>(ordering) => (items) => 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
Section titled “ordering”Ordering<A>
Returns
Section titled “Returns”(items) => readonly A[]
sortBy for sorting using a comparator function.
Example
Section titled “Example”splitAt
Section titled “splitAt”splitAt: (
index) => <A>(items) => 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>(items) => readonly [readonly A[], readonly A[]]
Example
Section titled “Example”tail: <
A>(items) =>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[]>
head for accessing the first element.
Example
Section titled “Example”take: (
count) => <A>(items) => readonlyA[]
Takes the first n elements from an array.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”<A>(items) => readonly A[]
Example
Section titled “Example”takeWhile
Section titled “takeWhile”takeWhile: <
A>(predicate) => (items) => 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”(item) => boolean
Returns
Section titled “Returns”(items) => readonly A[]
- dropWhile for discarding elements while a predicate holds.
- take for taking a fixed count of elements.
Example
Section titled “Example”traverse
Section titled “traverse”traverse:
object
Maps elements to an effectful container and aggregates the results.
traverse.Maybe
Section titled “traverse.Maybe”Maybe: <
A,B>(transform) => (items) =>Maybe<readonlyB[]> =traverseMaybe
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(item) => Maybe<B>
Returns
Section titled “Returns”(items) => Maybe<readonly B[]>
traverse.Result
Section titled “traverse.Result”Result: <
E,A,B>(transform) => (items) =>Result<E, readonlyB[]> =traverseResult
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(item) => Result<E, B>
Returns
Section titled “Returns”(items) => Result<E, readonly B[]>
traverse.Task
Section titled “traverse.Task”Task: <
A,B>(transform,options?) => (items) =>Task<readonlyB[]> =traverseTask
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(item) => Task<B>
options?
Section titled “options?”concurrency?
Section titled “concurrency?”number
Returns
Section titled “Returns”(items) => Task<readonly B[]>
traverse.Validation
Section titled “traverse.Validation”Validation: <
E,A,B>(transform) => (items) =>Validation<E, readonlyB[]> =traverseValidation
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(item) => Validation<E, B>
Returns
Section titled “Returns”(items) => Validation<E, readonly B[]>
unfold
Section titled “unfold”unfold: <
A,S>(initial,step) => readonlyA[]
Generates an array from an initial seed state until step 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>(items) => 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>(keySelector) => (items) => readonlyA[]
Removes duplicate elements by comparing the result of a key function.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”keySelector
Section titled “keySelector”(item) => B
Returns
Section titled “Returns”(items) => readonly A[]
Example
Section titled “Example”uniqWith
Section titled “uniqWith”uniqWith: <
A>(areEqual) => (items) => 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”areEqual
Section titled “areEqual”Equality<A>
Returns
Section titled “Returns”(items) => readonly A[]
Example
Section titled “Example”windowed
Section titled “windowed”windowed: (
windowSize,options?) => <A>(items) => 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 > items.length.
Parameters
Section titled “Parameters”windowSize
Section titled “windowSize”number
options?
Section titled “options?”number
Returns
Section titled “Returns”<A>(items) => readonly (readonly A[])[]
Example
Section titled “Example”zip: <
B>(other) => <A>(items) => 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>(items) => readonly (readonly [A, B])[]
zipWith for pairing elements with a custom combining function.
Example
Section titled “Example”zipWith
Section titled “zipWith”zipWith: <
A,B,C>(combine) => (other) => (items) => 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”combine
Section titled “combine”(first, second) => C
Returns
Section titled “Returns”(other) => (items) => readonly C[]
zip for pairing elements into 2-tuples.