Skip to content

Arr

const Arr: object

Defined in: Data/Arr.ts:1290

append: <A>(item) => (items) => NonEmptyArr<A>

Appends a value to the end of an array, returning a NonEmptyArr.

A

A

(items) => NonEmptyArr<A>

prepend for adding an element to the beginning.

pipe([1, 2], Arr.append(3)); // [1, 2, 3]

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.

number

<A>(items) => Maybe<A>

pipe([10, 20, 30], Arr.at(1));  // Some(20)
pipe([10, 20, 30], Arr.at(-1)); // Some(30)
pipe([10, 20, 30], Arr.at(5));  // None

chunkBy: <A, K>(keySelector) => (items) => readonly (readonly A[])[]

Groups consecutive elements that share the same key returned by keySelector.

A

K

(item) => K

(items) => readonly (readonly A[])[]

chunksOf for fixed-size chunking.

pipe(
  [1, 1, 2, 3, 3, 1],
  Arr.chunkBy((n) => n)
); // [[1, 1], [2], [3, 3], [1]]

chunksOf: (size) => <A>(items) => readonly (readonly A[])[]

Splits an array into chunks of the given size.

number

<A>(items) => readonly (readonly A[])[]

chunkBy for grouping consecutive elements sharing a key.

pipe([1, 2, 3, 4, 5], Arr.chunksOf(2)); // [[1, 2], [3, 4], [5]]

compact: <A>(items) => readonly A[]

Narrows a list of Maybe values down to a list of their underlying values, discarding all None instances.

A

readonly Maybe<A>[]

readonly A[]

separate for dividing Results into error and success arrays.

Arr.compact([Maybe.make.some(1), Maybe.make.none(), Maybe.make.some(3)]); // [1, 3]

concat: <A>(other) => (items) => readonly A[]

Concatenates a standard array with another array.

A

readonly A[]

(items) => readonly A[]

pipe([1, 2], Arr.concat([3, 4])); // [1, 2, 3, 4]

dedupeAdjacent: <A>(areEqual) => (items) => readonly A[]

Removes consecutive duplicate elements. An optional Equality<A> can be provided (defaults to Object.is).

A

Equality<A> = ...

(items) => readonly A[]

uniq for deduplicating across the entire array.

Arr.dedupeAdjacent()([1, 1, 2, 2, 1, 3]); // [1, 2, 1, 3]

drop: (count) => <A>(items) => readonly A[]

Drops the first n elements from an array.

number

<A>(items) => readonly A[]

  • take for keeping the first n elements.
  • dropWhile for discarding elements based on a predicate.
pipe([1, 2, 3, 4], Arr.drop(2)); // [3, 4]

dropWhile: <A>(predicate) => (items) => readonly A[]

Drops elements from the start while the predicate holds.

A

(item) => boolean

(items) => readonly A[]

  • takeWhile for keeping elements while a predicate holds.
  • drop for discarding a fixed count of elements.
pipe([1, 2, 3, 1], Arr.dropWhile(n => n < 3)); // [3, 1]

every: <A>(predicate) => (items) => boolean

Returns true if all elements satisfy the predicate.

A

(item) => boolean

(items) => boolean

some for checking whether any element satisfies a predicate.

pipe([1, 2, 3], Arr.every(n => n > 0)); // true

filter: {<A, B>(predicate): (items) => readonly B[]; <A>(predicate): (items) => readonly A[]; }

<A, B>(predicate): (items) => readonly B[]

Filters elements that satisfy the predicate.

A

B

(item) => item is B

(items) => readonly B[]

filterMap for filtering and mapping simultaneously.

pipe([1, 2, 3, 4], Arr.filter(n => n % 2 === 0)); // [2, 4]

<A>(predicate): (items) => readonly A[]

Filters elements that satisfy the predicate.

A

(item) => boolean

(items) => readonly A[]

filterMap for filtering and mapping simultaneously.

pipe([1, 2, 3, 4], Arr.filter(n => n % 2 === 0)); // [2, 4]

filterMap: <A, B>(transform) => (items) => readonly B[]

Maps each element to a Maybe and collects only the Some values. Combines map and filter in a single pass.

A

B

(item) => Maybe<B>

(items) => readonly B[]

filter for filtering with a boolean predicate.

const parseNum = (s: string): Maybe<number> => {
  const n = Number(s);
  return isNaN(n) ? Maybe.make.none() : Maybe.make.some(n);
};

pipe(["1", "abc", "3"], Arr.filterMap(parseNum)); // [1, 3]

findFirst: {<A, B>(predicate): (items) => Maybe<B>; <A>(predicate): (items) => Maybe<A>; }

<A, B>(predicate): (items) => Maybe<B>

Returns the first element matching the predicate, or None.

A

B

(item) => item is B

(items) => Maybe<B>

  • findLast for finding the last matching element.
  • findIndex for obtaining the index of the first matching element.
pipe([1, 2, 3, 4], Arr.findFirst(n => n > 2)); // Some(3)

<A>(predicate): (items) => Maybe<A>

Returns the first element matching the predicate, or None.

A

(item) => boolean

(items) => Maybe<A>

  • findLast for finding the last matching element.
  • findIndex for obtaining the index of the first matching element.
pipe([1, 2, 3, 4], Arr.findFirst(n => n > 2)); // Some(3)

findIndex: <A>(predicate) => (items) => Maybe<number>

Returns the index of the first element matching the predicate, or None.

A

(item) => boolean

(items) => Maybe<number>

findFirst for finding the matching element value.

pipe([1, 2, 3, 4], Arr.findIndex(n => n > 2)); // Some(2)

findLast: {<A, B>(predicate): (items) => Maybe<B>; <A>(predicate): (items) => Maybe<A>; }

<A, B>(predicate): (items) => Maybe<B>

Returns the last element matching the predicate, or None.

A

B

(item) => item is B

(items) => Maybe<B>

findFirst for finding the first matching element.

pipe([1, 2, 3, 4], Arr.findLast(n => n > 2)); // Some(4)

<A>(predicate): (items) => Maybe<A>

Returns the last element matching the predicate, or None.

A

(item) => boolean

(items) => Maybe<A>

findFirst for finding the first matching element.

pipe([1, 2, 3, 4], Arr.findLast(n => n > 2)); // Some(4)

findMap: <A, B>(transform) => (items) => Maybe<B>

Finds the first element in an array for which transform returns Some(b).

A

B

(item) => Maybe<B>

(items) => Maybe<B>

findFirst for finding elements with a boolean predicate.

pipe(
  ["1", "a", "2"],
  Arr.findMap((s) => isNaN(Number(s)) ? Maybe.make.none() : Maybe.make.some(Number(s)))
); // Some(1)

flatMap: <A, B>(transform) => (items) => readonly B[]

Maps each element to an array and flattens the result.

A

B

(item) => readonly B[]

(items) => readonly B[]

  • map for mapping without flattening.
  • flatten for flattening without mapping.
pipe([1, 2, 3], Arr.flatMap(n => [n, n * 10])); // [1, 10, 2, 20, 3, 30]

flatten: <A>(items) => readonly A[]

Flattens a nested array by one level.

A

readonly (readonly A[])[]

readonly A[]

flatMap for mapping elements to arrays before flattening.

Arr.flatten([[1, 2], [3], [4, 5]]); // [1, 2, 3, 4, 5]

frequencies: <A>(items) => ReadonlyMap<A, number>

Counts occurrences of each element in an array, returning a ReadonlyMap<A, number>.

A

readonly A[]

ReadonlyMap<A, number>

Arr.frequencies(["a", "b", "a", "c", "b", "a"]);
// ReadonlyMap { "a" => 3, "b" => 2, "c" => 1 }

groupBy: <A>(keySelector) => (items) => Record<string, NonEmptyArr<A>>

Groups elements by a key function.

A

(item) => string

(items) => Record<string, NonEmptyArr<A>>

indexBy for indexing elements into a Map.

pipe(
  ["apple", "avocado", "banana"],
  Arr.groupBy(s => s[0])
); // { a: ["apple", "avocado"], b: ["banana"] }

head: <A>(items) => Maybe<A>

Returns the first element of an array, or None if the array is empty.

A

readonly A[]

Maybe<A>

  • last for accessing the final element.
  • tail for all elements except the first.
Arr.head([1, 2, 3]); // Some(1)
Arr.head([]); // None

indexBy: <A, K>(keySelector) => (items) => ReadonlyMap<K, A>

Indexes elements of an array into a ReadonlyMap<K, A> using a key extraction function.

A

K

(item) => K

(items) => ReadonlyMap<K, A>

groupBy for grouping multiple items per key into arrays.

pipe(
  [{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }],
  Arr.indexBy((u) => u.id)
); // ReadonlyMap { 1 => { id: 1, name: "Alice" }, 2 => { id: 2, name: "Bob" } }

init: <A>(items) => Maybe<readonly A[]>

Returns all elements except the last, or None if the array is empty.

A

readonly A[]

Maybe<readonly A[]>

last for accessing the final element.

Arr.init([1, 2, 3]); // Some([1, 2])
Arr.init([]); // None

insertAt: <A>(index, item) => (items) => readonly A[]

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.

A

number

A

(items) => readonly A[]

removeAt for removing an element at an index.

pipe([1, 2, 3], Arr.insertAt(1, 99)); // [1, 99, 2, 3]
pipe([1, 2, 3], Arr.insertAt(0, 99)); // [99, 1, 2, 3]
pipe([1, 2, 3], Arr.insertAt(3, 99)); // [1, 2, 3, 99]

intersperse: <A>(separator) => (items) => readonly A[]

Inserts a separator between every element.

A

A

(items) => readonly A[]

pipe([1, 2, 3], Arr.intersperse(0)); // [1, 0, 2, 0, 3]

is: object = ArrIs

empty: <A>(items) => boolean

Returns true when the array is empty.

A

readonly A[]

boolean

nonEmpty for checking if an array contains elements.

nonEmpty: <A>(items) => items is NonEmptyArr<A>

Returns true when the array contains at least one element.

A

readonly A[]

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.

A

readonly A[]

Maybe<A>

  • head for accessing the first element.
  • init for all elements except the last.
Arr.last([1, 2, 3]); // Some(3)
Arr.last([]); // None

map: <A, B>(transform) => (items) => readonly B[]

Transforms each element of an array.

A

B

(item) => B

(items) => readonly B[]

pipe([1, 2, 3], Arr.map(n => n * 2)); // [2, 4, 6]

mapWithIndex: <A, B>(transform) => (items) => readonly B[]

Transforms each element using both its value and its zero-based index.

A

B

(index, item) => B

(items) => readonly B[]

map for mapping without indices.

pipe(
  ["a", "b", "c"],
  Arr.mapWithIndex((i, s) => ({ position: i + 1, value: s }))
); // [{ position: 1, value: "a" }, { position: 2, value: "b" }, { position: 3, value: "c" }]

NonEmpty: object = ArrNonEmpty

Utilities for working with guaranteed non-empty arrays (NonEmptyArr).

concat: <A>(other) => (items) => NonEmptyArr<A>

Concatenates a non-empty array with another array, preserving non-emptiness.

A

readonly A[]

(items) => NonEmptyArr<A>

pipe([1, 2] as Arr.NonEmpty<number>, Arr.NonEmpty.concat([3, 4])); // [1, 2, 3, 4]

from: object

array: <A>(items) => Maybe<NonEmptyArr<A>>

Refines a standard array to a NonEmptyArr, returning Some if length > 0, None otherwise.

A

readonly A[]

Maybe<NonEmptyArr<A>>

Arr.NonEmpty.from.array([1, 2]); // Some([1, 2])
Arr.NonEmpty.from.array([]);     // None

head: <A>(items) => A

Returns the first element of a non-empty array without wrapping in Maybe.

A

NonEmptyArr<A>

A

last for accessing the last element.

Arr.NonEmpty.head([1, 2, 3]); // 1

intersperse: <A>(separator) => (items) => NonEmptyArr<A>

Inserts a separator between every element, preserving non-emptiness.

A

A

(items) => NonEmptyArr<A>

pipe([1, 2, 3] as Arr.NonEmpty<number>, Arr.NonEmpty.intersperse(0)); // [1, 0, 2, 0, 3]

last: <A>(items) => A

Returns the last element of a non-empty array without wrapping in Maybe.

A

NonEmptyArr<A>

A

head for accessing the first element.

Arr.NonEmpty.last([1, 2, 3]); // 3

map: <A, B>(transform) => (items) => NonEmptyArr<B>

Transforms each element of a non-empty array, preserving non-emptiness.

A

B

(item) => B

(items) => NonEmptyArr<B>

pipe([1, 2, 3] as Arr.NonEmpty<number>, Arr.NonEmpty.map(n => n * 2)); // [2, 4, 6]

mapWithIndex: <A, B>(transform) => (items) => NonEmptyArr<B>

Transforms each element with its index, preserving non-emptiness.

A

B

(index, item) => B

(items) => NonEmptyArr<B>

pipe(["a", "b"] as Arr.NonEmpty<string>, Arr.NonEmpty.mapWithIndex((i, s) => `${i}:${s}`));
// ["0:a", "1:b"]

reduce: <A>(reducer) => (items) => A

Reduces a non-empty array using its first element as the initial accumulator.

A

(accumulator, item) => A

(items) => A

pipe([1, 2, 3] as Arr.NonEmpty<number>, Arr.NonEmpty.reduce((a, b) => a + b)); // 6

reverse: <A>(items) => NonEmptyArr<A>

Reverses a non-empty array, preserving non-emptiness.

A

NonEmptyArr<A>

NonEmptyArr<A>

pipe([1, 2, 3] as Arr.NonEmpty<number>, Arr.NonEmpty.reverse); // [3, 2, 1]

singleton: <A>(item) => NonEmptyArr<A>

Creates a NonEmptyArr containing a single element.

A

A

NonEmptyArr<A>

Arr.NonEmpty.singleton(42); // [42]

tail: <A>(items) => readonly A[]

Returns all elements except the first.

A

NonEmptyArr<A>

readonly A[]

Arr.NonEmpty.tail([1, 2, 3]); // [2, 3]
Arr.NonEmpty.tail([1]);       // []

partition: {<A, B>(predicate): (items) => readonly [readonly B[], readonly Exclude<A, B>[]]; <A>(predicate): (items) => readonly [readonly A[], readonly A[]]; }

<A, B>(predicate): (items) => readonly [readonly B[], readonly Exclude<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.

A

B

(item) => item is B

(items) => readonly [readonly B[], readonly Exclude<A, B>[]]

partitionMap for partitioning with a Result function.

pipe([1, 2, 3, 4], Arr.partition(n => n % 2 === 0)); // [[2, 4], [1, 3]]

<A>(predicate): (items) => readonly [readonly A[], readonly A[]]

Splits an array into two groups based on a predicate. First group contains elements that satisfy the predicate, second group contains the rest.

A

(item) => boolean

(items) => readonly [readonly A[], readonly A[]]

partitionMap for partitioning with a Result function.

pipe([1, 2, 3, 4], Arr.partition(n => n % 2 === 0)); // [[2, 4], [1, 3]]

partitionMap: <A, E, B>(transform) => (items) => readonly [readonly E[], readonly B[]]

Maps each element to a Result, and separates the results into a tuple of failures and successes.

A

E

B

(item) => Result<E, B>

(items) => readonly [readonly E[], readonly B[]]

  • partition for partitioning with a boolean predicate.
  • partitionMaybe for partitioning with a Maybe function.
pipe(
  [1, 2, 3, 4],
  Arr.partitionMap(n => n % 2 === 0 ? Result.make.ok(n) : Result.make.err(`odd: ${n}`))
); // [["odd: 1", "odd: 3"], [2, 4]]

partitionMaybe: <A, B>(transform) => (items) => readonly [readonly A[], readonly B[]]

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).

A

B

(item) => Maybe<B>

(items) => readonly [readonly A[], readonly B[]]

  • partitionMap for partitioning with a Result mapper.
  • partition for partitioning with a boolean predicate.
const parseNumber = (s: string) => isNaN(Number(s)) ? Maybe.make.none() : Maybe.make.some(Number(s));
pipe(["1", "abc", "3"], Arr.partitionMaybe(parseNumber)); // [["abc"], [1, 3]]

prepend: <A>(item) => (items) => NonEmptyArr<A>

Prepends a value to the beginning of an array, returning a NonEmptyArr.

A

A

(items) => NonEmptyArr<A>

append for adding an element to the end.

pipe([1, 2], Arr.prepend(0)); // [0, 1, 2]

reduce: <A, B>(initial, reducer) => (items) => B

Reduces an array from the left.

A

B

B

(accumulator, item) => B

(items) => B

scan for preserving intermediate accumulation states.

pipe([1, 2, 3], Arr.reduce(0, (acc, n) => acc + n)); // 6

removeAt: (index) => <A>(items) => readonly A[]

Returns a new array with the element at index removed. Returns the original array unchanged if index is out of bounds.

number

<A>(items) => readonly A[]

insertAt for inserting an element at an index.

pipe([1, 2, 3], Arr.removeAt(1)); // [1, 3]
pipe([1, 2, 3], Arr.removeAt(0)); // [2, 3]
pipe([1, 2, 3], Arr.removeAt(5)); // [1, 2, 3]

reverse: <A>(items) => readonly A[]

Reverses an array. Returns a new array.

A

readonly A[]

readonly A[]

Arr.reverse([1, 2, 3]); // [3, 2, 1]

scan: <A, B>(initial, reducer) => (items) => readonly B[]

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.

A

B

B

(accumulator, item) => B

(items) => readonly B[]

reduce for computing only the final accumulator value.

pipe([1, 2, 3], Arr.scan(0, (acc, n) => acc + n)); // [1, 3, 6]

separate: <E, A>(items) => readonly [readonly E[], readonly A[]]

Separates an array of Result values into two separate lists of errors and successes. Returns a tuple containing [errors, successes].

E

A

readonly Result<E, A>[]

readonly [readonly E[], readonly A[]]

compact for extracting Some values from Maybe instances.

Arr.separate([Result.make.ok(1), Result.make.err("bad"), Result.make.ok(3)]); // [["bad"], [1, 3]]

sequence: object

Sequences an array of effectful containers into a container of array.

Maybe: <A>(items) => Maybe<readonly A[]> = sequenceMaybe

A

readonly Maybe<A>[]

Maybe<readonly A[]>

Result: <E, A>(items) => Result<E, readonly A[]> = sequenceResult

E

A

readonly Result<E, A>[]

Result<E, readonly A[]>

Task: <A>(items) => Task<readonly A[]> = sequenceTask

A

readonly Task<A>[]

Task<readonly A[]>

Validation: <E, A>(items) => Validation<E, readonly A[]> = sequenceValidation

E

A

readonly Validation<E, A>[]

Validation<E, readonly A[]>

size: <A>(items) => number

Returns the length of an array.

A

readonly A[]

number

Arr.size([1, 2, 3]); // 3

some: <A>(predicate) => (items) => boolean

Returns true if any element satisfies the predicate.

A

(item) => boolean

(items) => boolean

every for checking whether all elements satisfy a predicate.

pipe([1, 2, 3], Arr.some(n => n > 2)); // true

sortBy: <A>(compare) => (items) => readonly A[]

Sorts an array using a comparison function. Returns a new array. To sort with a typed Ordering<A>, prefer Arr.sortWith.

A

(first, second) => number

(items) => readonly A[]

sortWith for sorting using typed Ordering instances.

pipe([3, 1, 2], Arr.sortBy((a, b) => a - b)); // [1, 2, 3]

sortWith: <A>(ordering) => (items) => readonly A[]

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.

A

Ordering<A>

(items) => readonly A[]

sortBy for sorting using a comparator function.

pipe([3, 1, 2], Arr.sortWith(Ordering.number)); // [1, 2, 3]

type Product = { price: number };
const products: Product[] = [{ price: 20 }, { price: 10 }];
const byPrice = pipe(Ordering.number, Ordering.by((p: Product) => p.price));
pipe(products, Arr.sortWith(byPrice));

splitAt: (index) => <A>(items) => readonly [readonly A[], readonly A[]]

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.

number

<A>(items) => readonly [readonly A[], readonly A[]]

pipe([1, 2, 3, 4], Arr.splitAt(2)); // [[1, 2], [3, 4]]
pipe([1, 2, 3], Arr.splitAt(0));    // [[], [1, 2, 3]]
pipe([1, 2, 3], Arr.splitAt(10));   // [[1, 2, 3], []]

tail: <A>(items) => Maybe<readonly A[]>

Returns all elements except the first, or None if the array is empty.

A

readonly A[]

Maybe<readonly A[]>

head for accessing the first element.

Arr.tail([1, 2, 3]); // Some([2, 3])
Arr.tail([]); // None

take: (count) => <A>(items) => readonly A[]

Takes the first n elements from an array.

number

<A>(items) => readonly A[]

  • drop for discarding the first n elements.
  • takeWhile for taking elements based on a predicate.
pipe([1, 2, 3, 4], Arr.take(2)); // [1, 2]

takeWhile: <A>(predicate) => (items) => readonly A[]

Takes elements from the start while the predicate holds.

A

(item) => boolean

(items) => readonly A[]

  • dropWhile for discarding elements while a predicate holds.
  • take for taking a fixed count of elements.
pipe([1, 2, 3, 1], Arr.takeWhile(n => n < 3)); // [1, 2]

traverse: object

Maps elements to an effectful container and aggregates the results.

Maybe: <A, B>(transform) => (items) => Maybe<readonly B[]> = traverseMaybe

A

B

(item) => Maybe<B>

(items) => Maybe<readonly B[]>

Result: <E, A, B>(transform) => (items) => Result<E, readonly B[]> = traverseResult

E

A

B

(item) => Result<E, B>

(items) => Result<E, readonly B[]>

Task: <A, B>(transform, options?) => (items) => Task<readonly B[]> = traverseTask

A

B

(item) => Task<B>

number

(items) => Task<readonly B[]>

Validation: <E, A, B>(transform) => (items) => Validation<E, readonly B[]> = traverseValidation

E

A

B

(item) => Validation<E, B>

(items) => Validation<E, readonly B[]>

unfold: <A, S>(initial, step) => readonly A[]

Generates an array from an initial seed state until step returns None.

A

S

S

(state) => Maybe<readonly [A, S]>

readonly A[]

Arr.unfold(1, (n) => n > 3 ? Maybe.make.none() : Maybe.make.some([n, n + 1]));
// [1, 2, 3]

uniq: <A>(items) => readonly A[]

Removes duplicate elements using strict equality.

A

readonly A[]

readonly A[]

  • uniqBy for deduplicating by a key projection.
  • uniqWith for deduplicating with custom equality.
Arr.uniq([1, 2, 2, 3, 1]); // [1, 2, 3]

uniqBy: <A, B>(keySelector) => (items) => readonly A[]

Removes duplicate elements by comparing the result of a key function.

A

B

(item) => B

(items) => readonly A[]

  • uniq for reference-equality deduplication.
  • uniqWith for deduplicating with custom equality.
pipe(
  [{id: 1, name: "a"}, {id: 1, name: "b"}, {id: 2, name: "c"}],
  Arr.uniqBy(x => x.id)
); // [{id: 1, name: "a"}, {id: 2, name: "c"}]

uniqWith: <A>(areEqual) => (items) => readonly A[]

Removes duplicate elements using a custom equality check. Preserves the order of first occurrences. Complements uniq (reference equality) and uniqBy (key extraction).

A

Equality<A>

(items) => readonly A[]

  • uniq for reference-equality deduplication.
  • uniqBy for key-based deduplication.
type Point = { x: number; y: number };
const eqPoint: Equality<Point> = (a, b) => a.x === b.x && a.y === b.y;

pipe(
  [{ x: 1, y: 1 }, { x: 2, y: 2 }, { x: 1, y: 1 }],
  Arr.uniqWith(eqPoint),
); // [{ x: 1, y: 1 }, { x: 2, y: 2 }]

windowed: (windowSize, options?) => <A>(items) => readonly (readonly A[])[]

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.

number

number

<A>(items) => readonly (readonly A[])[]

pipe([1, 2, 3, 4], Arr.windowed(2)); // [[1, 2], [2, 3], [3, 4]]
pipe([1, 2, 3, 4], Arr.windowed(2, { step: 2 })); // [[1, 2], [3, 4]]

zip: <B>(other) => <A>(items) => readonly (readonly [A, B])[]

Pairs up elements from two arrays. Stops at the shorter array.

B

readonly B[]

<A>(items) => readonly (readonly [A, B])[]

zipWith for pairing elements with a custom combining function.

pipe([1, 2, 3], Arr.zip(["a", "b"])); // [[1, "a"], [2, "b"]]

zipWith: <A, B, C>(combine) => (other) => (items) => readonly C[]

Combines elements from two arrays using a function. Stops at the shorter array.

A

B

C

(first, second) => C

(other) => (items) => readonly C[]

zip for pairing elements into 2-tuples.

pipe([1, 2], Arr.zipWith((a: number, b: string) => `${a}${b}`)(["a", "b"])); // ["1a", "2b"]