prelude-js logoprelude-js

preludejs/List API

Complete API reference for preludejs/List

preludejs/List API Reference

Core

all ƒ

Returns true only when every item satisfies the predicate; curried.

function all<A>(fn: Predicate<A>): (xs: readonly A[]) => boolean
function all<A>(fn: Predicate<A>, xs: readonly A[]): boolean

Parameters

ParameterTypeDescription
fnPredicate<A>

Example

all((x: number) => x > 0, [1, 2, 3]) //=> true

and ƒ

Returns true when every item in the list is truthy.

function and(xs: readonly unknown[]): boolean

Parameters

ParameterTypeDescription
xsreadonly unknown[]

Example

and([1, 2, 3]) //=> true

any ƒ

Returns true when at least one item satisfies the predicate; curried.

function any<A>(fn: Predicate<A>): (xs: readonly A[]) => boolean
function any<A>(fn: Predicate<A>, xs: readonly A[]): boolean

Parameters

ParameterTypeDescription
fnPredicate<A>

Example

any((x: number) => x > 2, [1, 2, 3]) //=> true

at ƒ

Returns the item at the given index; curried.

function at<A>(index: number): (xs: readonly A[]) => A | undefined
function at<A>(index: number, xs: readonly A[]): A | undefined

Parameters

ParameterTypeDescription
indexnumber

Example

at(1, ['a', 'b', 'c']) //=> 'b'

breakList ƒ

Splits the list at the first item that satisfies the predicate; curried.

function breakList<A>(fn: Predicate<A>): (xs: readonly A[]) => [A[], A[]]
function breakList<A>(fn: Predicate<A>, xs: readonly A[]): [A[], A[]]

Parameters

ParameterTypeDescription
fnPredicate<A>

Example

breakList((x: number) => x > 2, [1, 2, 3, 4]) //=> [[1, 2], [3, 4]]

compact ƒ

Removes falsy values from the list.

function compact<A>(xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
xsreadonly A[]

Example

compact([0, 1, false, 2]) //=> [1, 2]

concat ƒ

Concatenates a list of lists into a single list.

function concat<A>(xss: readonly (readonly A[])[]): A[]

Parameters

ParameterTypeDescription
xssreadonly (readonly A[])[]

Example

concat([[1, 2], [3], [4, 5]]) //=> [1, 2, 3, 4, 5]

concatMap ƒ

Maps a list to lists and concatenates the results; curried.

function concatMap<A, B>(fn: Mapper<A, readonly B[]>): (xs: readonly A[]) => B[]
function concatMap<A, B>(fn: Mapper<A, readonly B[]>, xs: readonly A[]): B[]

Parameters

ParameterTypeDescription
fnMapper<A, readonly B[]>

Example

concatMap((x: number) => [x, x], [1, 2, 3]) //=> [1, 1, 2, 2, 3, 3]

countBy ƒ

Counts items grouped by the key the accessor returns; curried.

function countBy<A, B>(fn: Accessor<A, B>): (xs: readonly A[]) => Record<string, number>
function countBy<A, B>(fn: Accessor<A, B>, xs: readonly A[]): Record<string, number>

Parameters

ParameterTypeDescription
fnAccessor<A, B>

Example

countBy(Math.floor, [4.2, 4.4, 9.8]) //=> { 4: 2, 9: 1 }

difference ƒ

Returns items present in the first list but absent from the rest.

function difference<A>(xs: readonly A[], ...yss: readonly (readonly A[])[]): A[]

Parameters

ParameterTypeDescription
xsreadonly A[]
yssreadonly (readonly A[])[]

Example

difference([1, 2, 3, 4], [1], [4]) //=> [2, 3]

drop ƒ

Drops the first n items from the list; curried.

function drop<A>(count: number): (xs: readonly A[]) => A[]
function drop<A>(count: number, xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
countnumber

Example

drop(2, [1, 2, 3, 4]) //=> [3, 4]

dropWhile ƒ

Drops leading items while the predicate holds; curried.

function dropWhile<A>(fn: Predicate<A>): (xs: readonly A[]) => A[]
function dropWhile<A>(fn: Predicate<A>, xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
fnPredicate<A>

Example

dropWhile((n: number) => n <= 3, [2, 3, 5, 1]) //=> [5, 1]

each ƒ

Applies a function to each item for its side effect; curried.

function each<A>(fn: (value: A, index: number, array: readonly A[]) => unknown): (xs: readonly A[]) => void
function each<A>(fn: (value: A, index: number, array: readonly A[]) => unknown, xs: readonly A[]): void

Parameters

ParameterTypeDescription
fn(value: A, index: number, array: readonly A[]) => unknown

Example

each((x: number) => console.log(x), [1, 2, 3]) //=> undefined

elem ƒ

Returns true when the value is present in the list; curried.

function elem<A>(value: A): (xs: readonly A[]) => boolean
function elem<A>(value: A, xs: readonly A[]): boolean

Parameters

ParameterTypeDescription
valueA

Example

elem(3, [1, 2, 3]) //=> true

elemIndex ƒ

Returns the index of the first item equal to the value, or -1; curried.

function elemIndex<A>(value: A): (xs: readonly A[]) => number
function elemIndex<A>(value: A, xs: readonly A[]): number

Parameters

ParameterTypeDescription
valueA

Example

elemIndex(3, [1, 2, 3]) //=> 2

elemIndices ƒ

Returns the indices of all items equal to the value; curried.

function elemIndices<A>(value: A): (xs: readonly A[]) => number[]
function elemIndices<A>(value: A, xs: readonly A[]): number[]

Parameters

ParameterTypeDescription
valueA

Example

elemIndices(2, [2, 1, 2]) //=> [0, 2]

empty ƒ

Returns true when the list has no items.

function empty<A>(xs: readonly A[]): boolean

Parameters

ParameterTypeDescription
xsreadonly A[]

Example

empty([]) //=> true

filter ƒ

Keeps the items that satisfy the predicate; curried.

function filter<A>(fn: Predicate<A>): (xs: readonly A[]) => A[]
function filter<A>(fn: Predicate<A>, xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
fnPredicate<A>

Example

filter((x: number) => x > 3, [1, 2, 3, 4, 5]) //=> [4, 5]

find ƒ

Returns the first item that satisfies the predicate, or undefined; curried.

function find<A>(fn: Predicate<A>): (xs: readonly A[]) => A | undefined
function find<A>(fn: Predicate<A>, xs: readonly A[]): A | undefined

Parameters

ParameterTypeDescription
fnPredicate<A>

Example

find((x: number) => x > 2, [1, 2, 3, 4]) //=> 3

findIndex ƒ

Returns the index of the first item that satisfies the predicate, or -1; curried.

function findIndex<A>(fn: Predicate<A>): (xs: readonly A[]) => number
function findIndex<A>(fn: Predicate<A>, xs: readonly A[]): number

Parameters

ParameterTypeDescription
fnPredicate<A>

Example

findIndex((x: number) => x > 2, [1, 2, 3]) //=> 2

findIndices ƒ

Returns the indices of all items that satisfy the predicate; curried.

function findIndices<A>(fn: Predicate<A>): (xs: readonly A[]) => number[]
function findIndices<A>(fn: Predicate<A>, xs: readonly A[]): number[]

Parameters

ParameterTypeDescription
fnPredicate<A>

Example

findIndices((x: number) => x > 1, [1, 2, 3]) //=> [1, 2]

first ƒ

Returns the first item of the list, or undefined. Alias of head.

function first<A>(xs: readonly A[]): A | undefined

Parameters

ParameterTypeDescription
xsreadonly A[]

Example

first([1, 2, 3]) //=> 1

flatten ƒ

function flatten<A>(xss: readonly Nested<A>[]): A[]

Parameters

ParameterTypeDescription
xssreadonly Nested<A>[]

fold ƒ

Left-associative fold over a list with an initial accumulator. Alias of foldl.

function fold<A, B>(fn: Reducer<A, B>): (initial: A) => (xs: readonly B[]) => A
function fold<A, B>(fn: Reducer<A, B>, initial: A): (xs: readonly B[]) => A
function fold<A, B>(fn: Reducer<A, B>, initial: A, xs: readonly B[]): A

Parameters

ParameterTypeDescription
fnReducer<A, B>

Example

fold((acc: number, x: number) => acc + x, 0, [1, 2, 3]) //=> 6

fold1 ƒ

Left fold over a non-empty list using its head as the seed. Alias of foldl1.

function fold1<A>(fn: (acc: A, value: A) => A): (xs: readonly A[]) => A
function fold1<A>(fn: (acc: A, value: A) => A, xs: readonly A[]): A

Parameters

ParameterTypeDescription
fn(acc: A, value: A) => A

Example

fold1((acc: number, x: number) => acc + x, [1, 2, 3]) //=> 6

foldl ƒ

Left-associative fold over a list with an initial accumulator; curried.

function foldl<A, B>(fn: Reducer<A, B>): (initial: A) => (xs: readonly B[]) => A
function foldl<A, B>(fn: Reducer<A, B>, initial: A): (xs: readonly B[]) => A
function foldl<A, B>(fn: Reducer<A, B>, initial: A, xs: readonly B[]): A

Parameters

ParameterTypeDescription
fnReducer<A, B>

Example

foldl((acc: number, x: number) => acc + x, 0, [1, 2, 3]) //=> 6

foldl1 ƒ

Left fold over a non-empty list using its head as the seed; curried.

function foldl1<A>(fn: (acc: A, value: A) => A): (xs: readonly A[]) => A
function foldl1<A>(fn: (acc: A, value: A) => A, xs: readonly A[]): A

Parameters

ParameterTypeDescription
fn(acc: A, value: A) => A

Example

foldl1((acc: number, x: number) => acc + x, [1, 2, 3]) //=> 6

foldr ƒ

Right-associative fold over a list with an initial accumulator; curried.

function foldr<A, B>(fn: (value: B, acc: A, index: number, array: readonly B[]) => A): (initial: A) => (xs: readonly B[]) => A
function foldr<A, B>(fn: (value: B, acc: A, index: number, array: readonly B[]) => A, initial: A): (xs: readonly B[]) => A
function foldr<A, B>(fn: (value: B, acc: A, index: number, array: readonly B[]) => A, initial: A, xs: readonly B[]): A

Parameters

ParameterTypeDescription
fn(value: B, acc: A, index: number, array: readonly B[]) => A

Example

foldr((x: string, acc: string) => x + acc, 'o', ['h', 'e', 'l', 'l']) //=> 'hello'

foldr1 ƒ

Right fold over a non-empty list using its last item as the seed; curried.

function foldr1<A>(fn: (value: A, acc: A) => A): (xs: readonly A[]) => A
function foldr1<A>(fn: (value: A, acc: A) => A, xs: readonly A[]): A

Parameters

ParameterTypeDescription
fn(value: A, acc: A) => A

Example

foldr1((x: number, y: number) => x - y, [1, 2, 3, 4, 9]) //=> 7

groupBy ƒ

Groups items into lists keyed by the value the function returns; curried.

function groupBy<A>(fn: Accessor<A, boolean | PropertyKey>): (xs: readonly A[]) => Record<string, A[]>
function groupBy<A>(fn: Accessor<A, boolean | PropertyKey>, xs: readonly A[]): Record<string, A[]>

Parameters

ParameterTypeDescription
fnAccessor<A, boolean | PropertyKey>

Example

groupBy(Math.floor, [4.2, 4.4, 9.8]) //=> { 4: [4.2, 4.4], 9: [9.8] }

head ƒ

Returns the first item of the list, or undefined.

function head<A>(xs: readonly A[]): A | undefined

Parameters

ParameterTypeDescription
xsreadonly A[]

Example

head([1, 2, 3]) //=> 1

initial ƒ

Returns all items but the last, or undefined for an empty list.

function initial<A>(xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
xsreadonly A[]

Example

initial([1, 2, 3, 4]) //=> [1, 2, 3]

intersection ƒ

Returns items present in the first list and every other list.

function intersection<A>(xs: readonly A[], ...yss: readonly (readonly A[])[]): A[]

Parameters

ParameterTypeDescription
xsreadonly A[]
yssreadonly (readonly A[])[]

Example

intersection([1, 2, 3], [2, 3, 4]) //=> [2, 3]

last ƒ

Returns the last item of the list, or undefined.

function last<A>(xs: readonly A[]): A | undefined

Parameters

ParameterTypeDescription
xsreadonly A[]

Example

last([1, 2, 3]) //=> 3

length ƒ

Returns the number of items in the list.

function length<A>(xs: readonly A[]): number

Parameters

ParameterTypeDescription
xsreadonly A[]

Example

length([1, 2, 3]) //=> 3

map ƒ

Applies a function to each item, returning a new list; curried.

function map<A, B>(fn: Mapper<A, B>): (xs: readonly A[]) => B[]
function map<A, B>(fn: Mapper<A, B>, xs: readonly A[]): B[]

Parameters

ParameterTypeDescription
fnMapper<A, B>

Example

map((x: number) => x + 1, [1, 2, 3]) //=> [2, 3, 4]

maximum ƒ

Returns the largest item in the list, or undefined when empty.

function maximum<A>(xs: readonly A[]): A | undefined

Parameters

ParameterTypeDescription
xsreadonly A[]

Example

maximum([1, 2, 3, 4, 5]) //=> 5

maximumBy ƒ

Returns the item with the largest value produced by the accessor; curried.

function maximumBy<A, B>(fn: Accessor<A, B>): (xs: readonly A[]) => A | undefined
function maximumBy<A, B>(fn: Accessor<A, B>, xs: readonly A[]): A | undefined

Parameters

ParameterTypeDescription
fnAccessor<A, B>

Example

maximumBy((s: string) => s.length, ['a', 'ccc', 'bb']) //=> 'ccc'

mean ƒ

Returns the arithmetic mean of a list of numbers.

function mean(xs: readonly number[]): number

Parameters

ParameterTypeDescription
xsreadonly number[]

Example

mean([1, 2, 3, 4, 5]) //=> 3

minimum ƒ

Returns the smallest item in the list, or undefined when empty.

function minimum<A>(xs: readonly A[]): A | undefined

Parameters

ParameterTypeDescription
xsreadonly A[]

Example

minimum([3, 1, 2]) //=> 1

minimumBy ƒ

Returns the item with the smallest value produced by the accessor; curried.

function minimumBy<A, B>(fn: Accessor<A, B>): (xs: readonly A[]) => A | undefined
function minimumBy<A, B>(fn: Accessor<A, B>, xs: readonly A[]): A | undefined

Parameters

ParameterTypeDescription
fnAccessor<A, B>

Example

minimumBy((s: string) => s.length, ['was', 'a', 'test']) //=> 'a'

notElem ƒ

Returns true when the value is absent from the list; curried.

function notElem<A>(value: A): (xs: readonly A[]) => boolean
function notElem<A>(value: A, xs: readonly A[]): boolean

Parameters

ParameterTypeDescription
valueA

Example

notElem(4, [1, 2, 3]) //=> true

or ƒ

Returns true when at least one item in the list is truthy.

function or(xs: readonly unknown[]): boolean

Parameters

ParameterTypeDescription
xsreadonly unknown[]

Example

or([0, '', 3]) //=> true

partition ƒ

Splits a list into items that pass and fail the predicate; curried.

function partition<A>(fn: Predicate<A>): (xs: readonly A[]) => [A[], A[]]
function partition<A>(fn: Predicate<A>, xs: readonly A[]): [A[], A[]]

Parameters

ParameterTypeDescription
fnPredicate<A>

Example

partition((x: number) => x > 2, [1, 2, 3, 4]) //=> [[3, 4], [1, 2]]

product ƒ

Returns the product of a list of numbers.

function product(xs: readonly number[]): number

Parameters

ParameterTypeDescription
xsreadonly number[]

Example

product([1, 2, 3]) //=> 6

range ƒ

Builds an inclusive list of numbers from from to to stepping by step.

function range(to: number, from?: number, step?: number): number[]

Parameters

ParameterTypeDescription
tonumber
fromnumber
stepnumber

Example

range(3) //=> [1, 2, 3]

reduce ƒ

Left-reduces a list with an initial accumulator; curried.

function reduce<A, B>(fn: Reducer<A, B>): (initial: A) => (xs: readonly B[]) => A
function reduce<A, B>(fn: Reducer<A, B>, initial: A): (xs: readonly B[]) => A
function reduce<A, B>(fn: Reducer<A, B>, initial: A, xs: readonly B[]): A

Parameters

ParameterTypeDescription
fnReducer<A, B>

Example

reduce((acc: number, x: number) => acc + x, 0, [1, 2, 3]) //=> 6

reject ƒ

Keeps the items that do not satisfy the predicate; curried.

function reject<A>(fn: Predicate<A>): (xs: readonly A[]) => A[]
function reject<A>(fn: Predicate<A>, xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
fnPredicate<A>

Example

reject((x: number) => x > 2, [1, 2, 3, 4]) //=> [1, 2]

reverse ƒ

Returns a new list with the items in reverse order.

function reverse<A>(xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
xsreadonly A[]

Example

reverse([1, 2, 3]) //=> [3, 2, 1]

scan ƒ

Like reduce but returns the list of successive accumulator values; curried.

function scan<A, B>(fn: Reducer<A, B>): (initial: A) => (xs: readonly B[]) => A[]
function scan<A, B>(fn: Reducer<A, B>, initial: A): (xs: readonly B[]) => A[]
function scan<A, B>(fn: Reducer<A, B>, initial: A, xs: readonly B[]): A[]

Parameters

ParameterTypeDescription
fnReducer<A, B>

Example

scan((a: number, b: number) => a + b, 0, [1, 2, 3]) //=> [0, 1, 3, 6]

scan1 ƒ

Like scan but seeds with the list head; curried.

function scan1<A>(fn: (acc: A, value: A) => A): (xs: readonly A[]) => A[] | undefined
function scan1<A>(fn: (acc: A, value: A) => A, xs: readonly A[]): A[] | undefined

Parameters

ParameterTypeDescription
fn(acc: A, value: A) => A

Example

scan1((a: number, b: number) => a + b, [1, 2, 3]) //=> [1, 3, 6]

scanl ƒ

Left scan over a list with an initial accumulator. Alias of scan.

function scanl<A, B>(fn: Reducer<A, B>): (initial: A) => (xs: readonly B[]) => A[]
function scanl<A, B>(fn: Reducer<A, B>, initial: A): (xs: readonly B[]) => A[]
function scanl<A, B>(fn: Reducer<A, B>, initial: A, xs: readonly B[]): A[]

Parameters

ParameterTypeDescription
fnReducer<A, B>

Example

scanl((a: number, b: number) => a + b, 0, [1, 2, 3]) //=> [0, 1, 3, 6]

scanl1 ƒ

Left scan over a list seeded with its head. Alias of scan1.

function scanl1<A>(fn: (acc: A, value: A) => A): (xs: readonly A[]) => A[] | undefined
function scanl1<A>(fn: (acc: A, value: A) => A, xs: readonly A[]): A[] | undefined

Parameters

ParameterTypeDescription
fn(acc: A, value: A) => A

Example

scanl1((a: number, b: number) => a + b, [1, 2, 3]) //=> [1, 3, 6]

scanr ƒ

Right scan over a list with an initial accumulator; curried.

function scanr<A, B>(fn: (value: B, acc: A, index: number, array: readonly B[]) => A): (initial: A) => (xs: readonly B[]) => A[]
function scanr<A, B>(fn: (value: B, acc: A, index: number, array: readonly B[]) => A, initial: A): (xs: readonly B[]) => A[]
function scanr<A, B>(fn: (value: B, acc: A, index: number, array: readonly B[]) => A, initial: A, xs: readonly B[]): A[]

Parameters

ParameterTypeDescription
fn(value: B, acc: A, index: number, array: readonly B[]) => A

Example

scanr((a: number, b: number) => a + b, 0, [1, 2, 3]) //=> [6, 5, 3, 0]

scanr1 ƒ

Right scan over a list seeded with its last item; curried.

function scanr1<A>(fn: (value: A, acc: A) => A): (xs: readonly A[]) => A[]
function scanr1<A>(fn: (value: A, acc: A) => A, xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
fn(value: A, acc: A) => A

Example

scanr1((a: number, b: number) => a + b, [1, 2, 3]) //=> [6, 5, 3]

slice ƒ

Returns the sublist between start and end; curried.

function slice<A>(start: number): (end: number) => (xs: readonly A[]) => A[]
function slice<A>(start: number, end: number): (xs: readonly A[]) => A[]
function slice<A>(start: number, end: number, xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
startnumber

Example

slice(1, 3, [1, 2, 3, 4]) //=> [2, 3]

sort ƒ

Returns a new list sorted with default comparison.

function sort<A>(xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
xsreadonly A[]

Example

sort([1, 3, 2]) //=> [1, 2, 3]

sortBy ƒ

Returns a new list sorted by the value the accessor returns; curried.

function sortBy<A, B>(fn: Accessor<A, B>): (xs: readonly A[]) => A[]
function sortBy<A, B>(fn: Accessor<A, B>, xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
fnAccessor<A, B>

Example

sortBy((s: string) => s.length, ['three', 'one', 'two']) //=> ['one', 'two', 'three']

sortWith ƒ

Returns a new list sorted with a custom comparator; curried.

function sortWith<A>(fn: Comparer<A>): (xs: readonly A[]) => A[]
function sortWith<A>(fn: Comparer<A>, xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
fnComparer<A>

Example

sortWith((a: number, b: number) => a - b, [3, 1, 2]) //=> [1, 2, 3]

span ƒ

Splits a list into the longest prefix that satisfies the predicate and the rest; curried.

function span<A>(fn: Predicate<A>): (xs: readonly A[]) => [A[], A[]]
function span<A>(fn: Predicate<A>, xs: readonly A[]): [A[], A[]]

Parameters

ParameterTypeDescription
fnPredicate<A>

Example

span((x: number) => x < 3, [1, 2, 3, 4]) //=> [[1, 2], [3, 4]]

splitAt ƒ

Splits a list into a prefix of length index and the remaining items; curried.

function splitAt<A>(count: number): (xs: readonly A[]) => [A[], A[]]
function splitAt<A>(count: number, xs: readonly A[]): [A[], A[]]

Parameters

ParameterTypeDescription
countnumber

Example

splitAt(2, [1, 2, 3, 4]) //=> [[1, 2], [3, 4]]

sum ƒ

Returns the sum of a list of numbers.

function sum(xs: readonly number[]): number

Parameters

ParameterTypeDescription
xsreadonly number[]

Example

sum([1, 2, 3, 4, 5]) //=> 15

tail ƒ

Returns all items but the first.

function tail<A>(xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
xsreadonly A[]

Example

tail([1, 2, 3]) //=> [2, 3]

take ƒ

Takes the first n items from the list; curried.

function take<A>(count: number): (xs: readonly A[]) => A[]
function take<A>(count: number, xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
countnumber

Example

take(2, [1, 2, 3, 4]) //=> [1, 2]

takeWhile ƒ

Takes leading items while the predicate holds; curried.

function takeWhile<A>(fn: Predicate<A>): (xs: readonly A[]) => A[]
function takeWhile<A>(fn: Predicate<A>, xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
fnPredicate<A>

Example

takeWhile((n: number) => n <= 3, [2, 3, 5, 1]) //=> [2, 3]

unfoldr ƒ

Builds a list by repeatedly applying a generator to a seed; curried.

function unfoldr<A, B>(fn: (seed: B) => [A, B] | undefined): (seed: B) => A[]
function unfoldr<A, B>(fn: (seed: B) => [A, B] | undefined, seed: B): A[]

Parameters

ParameterTypeDescription
fn(seed: B) => [A, B] | undefined

Example

unfoldr((n: number) => (n > 0 ? [n, n - 1] : undefined), 3) //=> [3, 2, 1]

union ƒ

Returns the unique items across all supplied lists.

function union<A>(xs: readonly A[], ...yss: readonly (readonly A[])[]): A[]

Parameters

ParameterTypeDescription
xsreadonly A[]
yssreadonly (readonly A[])[]

Example

union([1, 2, 3], [3, 4]) //=> [1, 2, 3, 4]

unique ƒ

Returns the list with duplicate items removed.

function unique<A>(xs: readonly A[]): A[]

Parameters

ParameterTypeDescription
xsreadonly A[]

Example

unique([1, 2, 2, 3, 1]) //=> [1, 2, 3]

uniqueBy ƒ

Returns items unique by the value the accessor returns; curried.

function uniqueBy<A, B>(fn: Accessor<A, B>): (xs: readonly A[]) => B[]
function uniqueBy<A, B>(fn: Accessor<A, B>, xs: readonly A[]): B[]

Parameters

ParameterTypeDescription
fnAccessor<A, B>

Example

uniqueBy((o: { id: number }) => o.id, [{ id: 1 }, { id: 1 }, { id: 2 }]) //=> [1, 2]

zip ƒ

Zips two lists into a list of pairs, truncating to the shorter; curried.

function zip<A, B>(xs: readonly A[], ys: readonly B[]): Pair<A, B>[]
function zip<A>(xs: readonly A[]): <B>(ys: readonly B[]) => Pair<A, B>[]

Parameters

ParameterTypeDescription
xsreadonly A[]
ysreadonly B[]

Example

zip([1, 2], [4, 5]) //=> [[1, 4], [2, 5]]

zipAll ƒ

Zips two lists into pairs, padding the shorter list with undefined.

function zipAll<A, B>(xs: readonly A[], ys: readonly B[]): Pair<A | undefined, B | undefined>[]

Parameters

ParameterTypeDescription
xsreadonly A[]
ysreadonly B[]

Example

zipAll([1, 2], [4]) //=> [[1, 4], [2, undefined]]

zipAllWith ƒ

Combines two lists with a function, padding the shorter with undefined; curried.

function zipAllWith<A, B, C>(fn: (left: A | undefined, right: B | undefined) => C): (xs: readonly A[], ys: readonly B[]) => C[]
function zipAllWith<A, B, C>(fn: (left: A | undefined, right: B | undefined) => C, xs: readonly A[]): (ys: readonly B[]) => C[]
function zipAllWith<A, B, C>(fn: (left: A | undefined, right: B | undefined) => C, xs: readonly A[], ys: readonly B[]): C[]

Parameters

ParameterTypeDescription
fn(left: A | undefined, right: B | undefined) => C

Example

zipAllWith((a, b) => [a, b], [1], [4, 5]) //=> [[1, 4], [undefined, 5]]

zipWith ƒ

Combines two lists element-wise with a function, truncating to the shorter; curried.

function zipWith<A, B, C>(fn: (left: A, right: B) => C): (xs: readonly A[], ys: readonly B[]) => C[]
function zipWith<A, B, C>(fn: (left: A, right: B) => C, xs: readonly A[]): (ys: readonly B[]) => C[]
function zipWith<A, B, C>(fn: (left: A, right: B) => C, xs: readonly A[], ys: readonly B[]): C[]

Parameters

ParameterTypeDescription
fn(left: A, right: B) => C

Example

zipWith((a: number, b: number) => a + b, [1, 2, 3], [3, 2, 1]) //=> [4, 4, 4]

On this page

preludejs/List API ReferenceCoreall ƒParametersExampleand ƒParametersExampleany ƒParametersExampleat ƒParametersExamplebreakList ƒParametersExamplecompact ƒParametersExampleconcat ƒParametersExampleconcatMap ƒParametersExamplecountBy ƒParametersExampledifference ƒParametersExampledrop ƒParametersExampledropWhile ƒParametersExampleeach ƒParametersExampleelem ƒParametersExampleelemIndex ƒParametersExampleelemIndices ƒParametersExampleempty ƒParametersExamplefilter ƒParametersExamplefind ƒParametersExamplefindIndex ƒParametersExamplefindIndices ƒParametersExamplefirst ƒParametersExampleflatten ƒParametersfold ƒParametersExamplefold1 ƒParametersExamplefoldl ƒParametersExamplefoldl1 ƒParametersExamplefoldr ƒParametersExamplefoldr1 ƒParametersExamplegroupBy ƒParametersExamplehead ƒParametersExampleinitial ƒParametersExampleintersection ƒParametersExamplelast ƒParametersExamplelength ƒParametersExamplemap ƒParametersExamplemaximum ƒParametersExamplemaximumBy ƒParametersExamplemean ƒParametersExampleminimum ƒParametersExampleminimumBy ƒParametersExamplenotElem ƒParametersExampleor ƒParametersExamplepartition ƒParametersExampleproduct ƒParametersExamplerange ƒParametersExamplereduce ƒParametersExamplereject ƒParametersExamplereverse ƒParametersExamplescan ƒParametersExamplescan1 ƒParametersExamplescanl ƒParametersExamplescanl1 ƒParametersExamplescanr ƒParametersExamplescanr1 ƒParametersExampleslice ƒParametersExamplesort ƒParametersExamplesortBy ƒParametersExamplesortWith ƒParametersExamplespan ƒParametersExamplesplitAt ƒParametersExamplesum ƒParametersExampletail ƒParametersExampletake ƒParametersExampletakeWhile ƒParametersExampleunfoldr ƒParametersExampleunion ƒParametersExampleunique ƒParametersExampleuniqueBy ƒParametersExamplezip ƒParametersExamplezipAll ƒParametersExamplezipAllWith ƒParametersExamplezipWith ƒParametersExample