Array
Utility functions for Array.
all
Returns true if all elements of the array match the predicate function, otherwise, returns false.
function all<A>(xs: Array<A>, predicateFn: (_1: A) => boolean): boolean
function all<A>(predicateFn: (_1: A) => boolean): (xs: Array<A>) => boolean
A.all(['hello', 'world'], value => value.length > 0) // → true
pipe(
[1, 2, 3, 4, 5],
A.all(value => value > 3),
) // → false
any
Returns true if at least one of the elements of the array match the predicate function, otherwise, returns false.
function any<A>(xs: Array<A>, predicateFn: (_1: A) => boolean): boolean
function any<A>(predicateFn: (_1: A) => boolean): (xs: Array<A>) => boolean
A.any(['', 'hello', 'world'], value => value.length > 0) // → true
pipe(
[1, 2, 3, 4, 5],
A.any(value => value > 5),
) // → false
append
Adds a single element to the end of an array.
function append<A>(xs: Array<A>, element: A): Array<A>
function append<A>(element: A): (xs: Array<A>) => Array<A>
at
Alias for get.
function at<A>(xs: Array<A>, index: number): Option<A>
function at<A>(index: number): (xs: Array<A>) => Option<A>
concat
Returns a new array containing the concatenation of two provided arrays.
function concat<A>(xs1: Array<A>): (xs0: Array<A>) => Array<A>
function concat<A>(xs0: Array<A>, xs1: Array<A>): Array<A>
concatMany
Returns a new array as the concatenation of the provided array of arrays.
function concatMany<A>(xs: Array<Array<A>>): Array<A>
copy
Returns a copy of the provided array.
function copy<A>(xs: Array<A>): Array<A>
deepFlat
Creates a new array with all sub-array elements concatenated into it recursively up to the Infinite depth.
function deepFlat<A>(xs: Array<A>): Array<ExtractNested<A>>
difference
Returns elements from the first array, not existing in the second array.
function difference<A>(ys: Array<A>): (xs: Array<A>) => Array<A>
function difference<A>(xs: Array<A>, ys: Array<A>): Array<A>
A.difference([1, 2, 3, 4], [3, 4, 5, 6]) // → [1, 2]
pipe([5, 2, 3, 5, 6], A.difference([5, 2, 3, 1, 5, 4])) // → [6]
drop
Returns a new array that does not contain the first n elements of the provided array, or an empty array if n is either less than 0 or greater than the length of the provided array.
function drop<A>(xs: Array<A>, n: number): Array<A>
function drop<A>(n: number): (xs: Array<A>) => Array<A>
A.drop([1], 1) // → []
A.drop([1, 2, 3], 4) // → []
A.drop([1, 2, 3], 2) // → [3]
pipe([1, 2, 3, 4], A.drop(2)) // → [3, 4]
dropExactly
Returns a new array (Some(xs)) that does not contain the first n elements of the provided array, or None if n is either less than 0 or greater than the length of the provided array.
function dropExactly<A>(xs: Array<A>, n: number): Option<Array<A>>
function dropExactly<A>(n: number): (xs: Array<A>) => Option<Array<A>>
dropWhile
Drops elements from the beginning of the array until an element is reached which does not satisfy the given predicate.
function dropWhile<A>(xs: Array<A>, predicateFn: (_1: A) => boolean): Array<A>
function dropWhile<A>(predicateFn: (_1: A) => boolean): (xs: Array<A>) => Array<A>
eq
Returns false if length of both arrays is not the same, otherwise compares elements one by one using the comparator.
function eq<A>(xs0: Array<A>, xs1: Array<A>, comparatorFn: (_1: A, _2: A) => boolean): boolean
function eq<A>(xs1: Array<A>, comparatorFn: (_1: A, _2: A) => boolean): (xs0: Array<A>) => boolean
every
Returns `true`` if all elements satisfy the given predicate.
function every<A>(xs: Array<A>, fn: (_1: A) => boolean): boolean
function every<A>(fn: (_1: A) => boolean): (xs: Array<A>) => boolean
filter
Returns a new array that keep all elements satisfy the given predicate.
function filter<A, B extends A>(xs: Array<A>, predicateFn: (value: A) => value is B): Array<B>
function filter<A, B extends A>(predicateFn: (value: A) => value is B): (xs: Array<A>) => Array<B>
function filter<A>(xs: Array<A>, predicateFn: (value: A) => boolean): Array<A>
function filter<A>(predicateFn: (value: A) => boolean): (xs: Array<A>) => Array<A>
A.filter([1, 2, 3, 4], value => value % 2 === 0) // → [2, 4]
pipe(
[1, 2, 3, 4, 5, 6, 7, 8, 9],
A.filter(value => value % 2 === 0),
) // → [2, 4, 6, 8]
pipe(
['hello', 'wo', 'rld'],
A.filter(value => value.length < 4),
) // → ['wo', 'rld']
filterMap
Returns a new array that keep all elements that return Some(value) applied within predicateFn.
function filterMap<A, B>(xs: Array<A>, predicateFn: (_1: A) => Option<B>): Array<B>
function filterMap<A, B>(predicateFn: (_1: A) => Option<B>): (xs: Array<A>) => Array<B>
A.filterMap(['', 'hello', 'world', ''], value => {
return value.length > 0 ? O.Some(value.length) : O.None
}) // → [5, 5]
pipe(
[1, 2, 3, 4, 5],
A.filterMap(value => {
return value % 2 === 0 ? O.Some(value * 2) : O.None
}),
) // → [4, 8]
filterWithIndex
Returns a new array that keep all elements satisfy the given predicate (which take two arguments: the element for the array and its index).
function filterWithIndex<A, B extends A>(xs: Array<A>, predicateFn: (index: number, value: A) => value is B): Array<B>
function filterWithIndex<A, B extends A>(predicateFn: (index: number, value: A) => value is B): (xs: Array<A>) => Array<B>
function filterWithIndex<A>(xs: Array<A>, predicateFn: (index: number, value: A) => boolean): Array<A>
function filterWithIndex<A>(predicateFn: (index: number, value: A) => boolean): (xs: Array<A>) => Array<A>
find
Alias for getBy.
function find<A>(xs: Array<A>, predicateFn: (_1: A) => boolean): Option<A>
function find<A>(predicateFn: (_1: A) => boolean): (xs: Array<A>) => Option<A>
flat
Creates a new array with all sub-array elements concatenated into it (the single level depth).
function flat<A>(xs: Array<A>): Array<A extends Array<infer B> ? B : A>
flip
Returns a new tuple with the reverse order of the elements.
function flip<A, B>(xs: readonly [A, B]): readonly [B, A]
A.flip([1, 2]) // → [2, 1]
pipe(
{ name: 'Joe', location: 'Warsaw' },
D.toPairs,
A.map(A.flip),
D.fromPairs,
) // → { Joe: 'name', Warsaw: 'location' }
forEach
Calls fn on each element of the provided array.
function forEach<A>(xs: Array<A>, fn: (_1: A) => void): void
function forEach<A>(fn: (_1: A) => void): (xs: Array<A>) => void
forEachWithIndex
Calls fn (which takes two arguments: the element from array and its index) on each element of the provided array.
function forEachWithIndex<A>(xs: Array<A>, fn: (_1: number, _2: A) => void): void
function forEachWithIndex<A>(fn: (_1: number, _2: A) => void): (xs: Array<A>) => void
get
Returns Some(value) at the given index, or None if the given index is out of range.
function get<A>(xs: Array<A>, index: number): Option<A>
function get<A>(index: number): (xs: Array<A>) => Option<A>
getBy
Returns Some(value) for the first element in the array that satisifies the given predicate function, or None if no element satisifies the predicate.
function getBy<A>(xs: Array<A>, predicateFn: (_1: A) => boolean): Option<A>
function getBy<A>(predicateFn: (_1: A) => boolean): (xs: Array<A>) => Option<A>
getIndexBy
Returns Some(index) for the first value in the provided array that satisifies the predicate function.
function getIndexBy<A>(xs: Array<A>, predicateFn: (_1: A) => boolean): Option<number>
function getIndexBy<A>(predicateFn: (_1: A) => boolean): (xs: Array<A>) => Option<number>
getUndefined
Returns value at the given index, or undefined if the given index is out of range.
function getUndefined<A>(xs: Array<A>, index: number): A | undefined
function getUndefined<A>(index: number): (xs: Array<A>) => A | undefined
getUnsafe
Returns value at the given index (use only if you're entirely sure that a value exists at the given index).
function getUnsafe<A>(xs: Array<A>, index: number): A
function getUnsafe<A>(index: number): (xs: Array<A>) => A
groupBy
Splits the given array into sub-arrays in an object, grouped by the result of running each value through the provided function.
function groupBy<A, B extends PropertyKey>(xs: Array<A>, groupFn: (item: A) => B): Partial<Record<B, readonly [A, ...A[]]>>
function groupBy<A, B extends PropertyKey>(groupFn: (item: A) => B): (xs: Array<A>) => Partial<Record<B, readonly [A, ...A[]]>>
head
Returns Some(value) where value is the first element of the array, or None if the given array is empty.
function head<A>(xs: Array<A>): Option<A>
includes
Returns true if the provided value is equal to at least one element of the given array.
function includes<A>(xs: Array<A>, value: A): boolean
function includes<A>(value: A): (xs: Array<A>) => boolean
init
Returns a new array (Some(xs)) with all elements except the last of the provided array.
function init<A>(xs: Array<A>): Option<Array<A>>
initOrEmpty
Returns a new array with all elements except the last of the provided array, or an empty array if the given array is empty.
function initOrEmpty<A>(xs: Array<A>): Array<A>
insertAt
Creates a new array that inserts the given value at the given index (no insertion is made if the index is out of range).
function insertAt<A>(xs: Array<A>, targetIndex: number, element: A): Array<A>
function insertAt<A>(targetIndex: number, element: A): (xs: Array<A>) => Array<A>
intersection
Returns intersection of two arrays.
function intersection<A>(ys: Array<A>): (xs: Array<A>) => Array<A>
function intersection<A>(xs: Array<A>, ys: Array<A>): Array<A>
A.intersection([1, 2, 3, 4], [3, 4, 5, 6]) // → [3, 4]
pipe([5, 2, 3, 5, 6], A.intersection([5, 2, 3, 1, 5, 4])) // → [5, 2, 3]
intersperse
Creates a new array with the separator interposed between elements.
function intersperse<A>(xs: Array<A>, delimiter: A): Array<A>
function intersperse<A>(delimiter: A): (xs: Array<A>) => Array<A>
isEmpty
Determines whether the given array is empty.
function isEmpty<A>(xs: Array<A>): boolean
A.isEmpty(['hello', 'world']) // → false
A.isEmpty([]) // → true
pipe([1, 2, 3], A.isEmpty) // → false
isNotEmpty
Determines whether the given array is not empty.
function isNotEmpty<A>(xs: Array<A>): boolean
A.isNotEmpty(['hello', 'world']) // → true
A.isNotEmpty([]) // → false
pipe([1, 2, 3], A.isNotEmpty) // → true
join
Converts each element of the array to a string and concatenates them, separated by the given string.
function join<A>(xs: Array<A>, delimiter: string): string
function join<A>(delimiter: string): (xs: Array<A>) => string
keep
Alias for filter.
function keep<A, B extends A>(xs: Array<A>, predicateFn: (value: A) => value is B): Array<B>
function keep<A, B extends A>(predicateFn: (value: A) => value is B): (xs: Array<A>) => Array<B>
function keep<A>(xs: Array<A>, predicateFn: (value: A) => boolean): Array<A>
function keep<A>(predicateFn: (value: A) => boolean): (xs: Array<A>) => Array<A>
keepMap
Alias for filterMap.
function keepMap<A, B>(xs: Array<A>, predicateFn: (_1: A) => Option<B>): Array<B>
function keepMap<A, B>(predicateFn: (_1: A) => Option<B>): (xs: Array<A>) => Array<B>
keepWithIndex
Alias for filterWithIndex.
function keepWithIndex<A, B extends A>(xs: Array<A>, predicateFn: (index: number, value: A) => value is B): Array<B>
function keepWithIndex<A, B extends A>(predicateFn: (index: number, value: A) => value is B): (xs: Array<A>) => Array<B>
function keepWithIndex<A>(xs: Array<A>, predicateFn: (index: number, value: A) => boolean): Array<A>
function keepWithIndex<A>(predicateFn: (index: number, value: A) => boolean): (xs: Array<A>) => Array<A>
last
Returns the last element (Some(value)) in the array, or None if the given array is empty.
function last<A>(xs: Array<A>): Option<A>
length
Returns the size of the provided array.
function length<A>(xs: Array<A>): number
A.length(['hello', 'world']) // → 2
pipe([0, 2, 4], A.length) // → 3
make
Returns a new array of size n populated by element, or an empty array if n is negative.
function make<A>(n: number, element: A): Array<A>
function make<A>(element: A): (n: number) => Array<A>
A.make(-1, 'hello') // → []
A.make(3, 1) // → [1, 1, 1]
pipe(2, A.make('hello')) // → ['hello', 'hello']
makeEmpty
Creates an empty array. Alternative for const xs = [] as ReadonlyArray<A>.
function makeEmpty<A>(): Array<A>
A.makeEmpty<number>() // → []
makeWithIndex
Returns a new array of size n populated by mapFn(index), or an empty array if n is negative.
function makeWithIndex<A>(n: number, mapFn: (_1: number) => A): Array<A>
function makeWithIndex<A>(mapFn: (_1: number) => A): (n: number) => Array<A>
A.makeWithIndex(5, index => index * 2) // → [0, 2, 4, 6, 8]
map
Returns a new array by calling mapFn for each element of the provided array.
function map<A, B>(xs: Array<A>, mapFn: (_1: A) => B): Array<B>
function map<A, B>(mapFn: (_1: A) => B): (xs: Array<A>) => Array<B>
mapWithIndex
Returns a new array by calling mapFn (which takes two arguments: the element from array and its index) for each element of the provided array.
function mapWithIndex<A, B>(xs: Array<A>, mapFn: (_1: number, _2: A) => B): Array<B>
function mapWithIndex<A, B>(mapFn: (_1: number, _2: A) => B): (xs: Array<A>) => Array<B>
partition
Splits the provided array into two separate arrays - one containing elements which satisfy the predicate, and the other array containing the elements which do not satisfy the predicate.
function partition<A, B extends A>(xs: Array<A>, predicateFn: (value: A) => value is B): readonly [Array<B>, Array<Exclude<A, B>>]
function partition<A, B extends A>(predicateFn: (value: A) => value is B): (xs: Array<A>) => readonly [Array<B>, Array<Exclude<A, B>>]
function partition<A>(xs: Array<A>, predicateFn: (value: A) => boolean): readonly [Array<A>, Array<A>]
function partition<A>(predicateFn: (value: A) => boolean): (xs: Array<A>) => readonly [Array<A>, Array<A>]
A.partition([1, 2, 3, 4], value => value > 2) // → [[3, 4],[1, 2]]
pipe([1, 'hello', 2, 'world'], A.partition(G.isString)) // → [['hello', 'world'], [1, 2]]
prepend
Prepends a single element to the start of the given array.
function prepend<A>(xs: Array<A>, element: A): Array<A>
function prepend<A>(element: A): (xs: Array<A>) => Array<A>
prependToAll
Returns a new array which contains the given delimiter inserted before every element in the provided array.
function prependToAll<A>(xs: Array<A>, delimiter: A): Array<A>
function prependToAll<A>(delimiter: A): (xs: Array<A>) => Array<A>
range
Returns a new inclusive array of numbers from start to finish (it returns an empty array when start > finish).
function range(finish: number): (start: number) => Array<number>
function range(start: number, finish: number): Array<number>
rangeBy
Returns a new inclusive array of numbers from start to finish (it returns an empty array when step is 0 or negative, it also returns an empty array when start > finish).
function rangeBy(finish: number, step: number): (start: number) => Array<number>
function rangeBy(start: number, finish: number, step: number): Array<number>
reduce
Applies reduceFn (which has two parameters: an accumulator which starts with a value of initialValue and the next value from the array) to each element of the provided array, and eventually it returns the final value of the accumulator.
function reduce<A, B>(xs: Array<A>, initialValue: B, reduceFn: (_1: B, _2: A) => B): B
function reduce<A, B>(initialValue: B, reduceFn: (_1: B, _2: A) => B): (xs: Array<A>) => B
reduceReverse
Works like A.reduce, except that the function reduceFn is applied to each item of xs from the last back to the first.
function reduceReverse<A, B>(xs: Array<A>, initialValue: B, reduceFn: (_1: B, _2: A) => B): B
function reduceReverse<A, B>(initialValue: B, reduceFn: (_1: B, _2: A) => B): (xs: Array<A>) => B
reduceWithIndex
Applies reduceFn (which has three parameters: an accumulator which starts with a value of initialValue, the next value from the array and its index) to each element of the provided array, and eventually it returns the final value of the accumulator.
function reduceWithIndex<A, B>(xs: Array<A>, initialValue: B, reduceFn: (_1: B, _2: A, _3: number) => B): B
function reduceWithIndex<A, B>(initialValue: B, reduceFn: (_1: B, _2: A, _3: number) => B): (xs: Array<A>) => B
reject
Returns a new array of elements from the provided array which do not satisfy the given predicate.
function reject<A>(xs: Array<A>, predicateFn: (_1: A) => boolean): Array<A>
function reject<A>(predicateFn: (_1: A) => boolean): (xs: Array<A>) => Array<A>
rejectWithIndex
Returns a new array of elements from the provided array which do not satisfy the given predicate (which take two arguments: the element for the array and its index).
function rejectWithIndex<A>(xs: Array<A>, predicateFn: (_1: number, _2: A) => boolean): Array<A>
function rejectWithIndex<A>(predicateFn: (_1: number, _2: A) => boolean): (xs: Array<A>) => Array<A>
removeAt
Creates a new array without the element at the given index (the original array if the index is out of range).
function removeAt<A>(xs: Array<A>, targetIndex: number): Array<A>
function removeAt<A>(targetIndex: number): (xs: Array<A>) => Array<A>
removeFirst
Creates a copy of the given array with the first occurrence of the given element removed
function removeFirst<A>(xs: Array<A>, value: A): Array<A>
function removeFirst<A>(value: A): (xs: Array<A>) => Array<A>
A.removeFirst(['hello', 'hello', 'world'], 'hello') // → ['hello', 'world']
pipe([4, 5, 2, 1, 3], A.removeFirst(1)) // → [4, 5, 2, 3]
removeFirstBy
Removes the first occurrence of the given value from the array, using the given equality function.
function removeFirstBy<A, B>(xs: Array<A>, value: B, predicateFn: (_1: A, _2: B) => boolean): Array<A>
function removeFirstBy<A, B>(value: B, predicateFn: (_1: A, _2: B) => boolean): (xs: Array<A>) => Array<A>
A.removeFirstBy([1, 2, 1, 3, 4], 2, N.gt) // → [1, 2, 1, 4]
pipe(
['hello', 'wrld', 'world'],
A.removeFirstBy(4, (str, length) => str.length === length),
) // → ['hello', 'world']
repeat
Alias for make.
function repeat<A>(n: number, element: A): Array<A>
function repeat<A>(element: A): (n: number) => Array<A>
replaceAt
Creates a new array by replacing the value at the given index with the given value (no replacement is made if the index is out of range).
function replaceAt<A>(xs: Array<A>, targetIndex: number, element: A): Array<A>
function replaceAt<A>(targetIndex: number, element: A): (xs: Array<A>) => Array<A>
reverse
Returns a new array with the elements of the provided array in reverse order.
function reverse<A>(xs: Array<A>): Array<A>
A.reverse([1, 2, 3, 4, 5]) // → [5, 4, 3, 2, 1]
pipe(['hello', 'world'], A.reverse) // → ['world', 'hello']
shuffle
Returns a new array with elements in the original array randomly shuffled.
function shuffle<A>(xs: Array<A>): Array<A>
slice
Returns a new array with the len elements of the given array starting at offset (offset can be negative).
function slice<A>(xs: Array<A>, offset: number, len: number): Array<A>
function slice<A>(offset: number, len: number): (xs: Array<A>) => Array<A>
sliceToEnd
Returns a new array with the elements of the given array starting at offset (offset can be negative).
function sliceToEnd<A>(xs: Array<A>, offset: number): Array<A>
function sliceToEnd<A>(offset: number): (xs: Array<A>) => Array<A>
some
Returns true if at least one of the elements in the given array satifies the predicate.
function some<A>(xs: Array<A>, fn: (_1: A) => boolean): boolean
function some<A>(fn: (_1: A) => boolean): (xs: Array<A>) => boolean
sort
Returns a new array, sorted according to the comparator function.
function sort<A>(xs: Array<A>, sortFn: (_1: A, _2: A) => number): Array<A>
function sort<A>(sortFn: (_1: A, _2: A) => number): (xs: Array<A>) => Array<A>
sortBy
Returns a new array, sorted according to the provided function.
function sortBy<A, B>(xs: Array<A>, sortFn: (_1: A) => B): Array<A>
function sortBy<A, B>(sortFn: (_1: A) => B): (xs: Array<A>) => Array<A>
splitAt
Returns two arrays (Some([xs, ys])), with the original array divided at the given index, or None if the index is out of range.
function splitAt<A>(xs: Array<A>, offset: number): Option<readonly [Array<A>, Array<A>]>
function splitAt<A>(offset: number): (xs: Array<A>) => Option<readonly [Array<A>, Array<A>]>
splitEvery
Returns an array of arrays, where each of the inner arrays has length equal to the provided size parameter.
function splitEvery<A>(xs: Array<A>, size: number): Array<Array<A>>
function splitEvery<A>(size: number): (xs: Array<A>) => Array<Array<A>>
swapAt
Creates a new array with the elements at the two given indexes swapped (the original array if the index is out of range).
function swapAt<A>(xs: Array<A>, targetIndex: number, swapIndex: number): Array<A>
function swapAt<A>(targetIndex: number, swapIndex: number): (xs: Array<A>) => Array<A>
tail
Returns a new array containing all but the the first element of the provided array, or None if the given array is empty (has no tail).
function tail<A>(xs: Array<A>): Option<Array<A>>
A.tail([1, 2, 3]) // → Some([2, 3])
A.tail([1]) // → Some([])
A.tail([]) // → None
pipe([1, 2, 3, 4], A.tail) // → Some([2, 3, 4])
tailOrEmpty
Returns a new array containing all but the first element of the provided array, or an empty array if the given array is empty (has no tail).
function tailOrEmpty<A>(xs: Array<A>): Array<A>
take
Returns a new array including the first n elements of the provided array, or an empty array if n is either negative or greater than the length of the provided array.
function take<A>(xs: Array<A>, n: number): Array<A>
function take<A>(n: number): (xs: Array<A>) => Array<A>
takeExactly
Returns a new array (Some(xs)) with the first n elements of the provided array, or None if n is either negative or greater than the length of the provided array.
function takeExactly<A>(xs: Array<A>, n: number): Option<Array<A>>
function takeExactly<A>(n: number): (xs: Array<A>) => Option<Array<A>>
takeWhile
Returns a new array, filled with elements from the provided array until an element doesn't pass the provided predicate.
function takeWhile<A>(xs: Array<A>, predicateFn: (_1: A) => boolean): Array<A>
function takeWhile<A>(predicateFn: (_1: A) => boolean): (xs: Array<A>) => Array<A>
tap
Applies a side-effect function on each element of the provided array.
function tap<A>(xs: Array<A>, fn: (_1: A) => void): Array<A>
function tap<A>(fn: (_1: A) => void): (xs: Array<A>) => Array<A>
toTuple
Converts the given array to the TypeScript's tuple.
function toTuple<T extends Array<any>>(xs: readonly [...T]): readonly [...T]
uncons
Splits the provided array into head and tail parts (as a tuple), but only if the array is not empty.
function uncons<A>(xs: Array<A>): Option<readonly [A, Array<A>]>
union
Returns union of two arrays.
function union<A>(ys: Array<A>): (xs: Array<A>) => Array<A>
function union<A>(xs: Array<A>, ys: Array<A>): Array<A>
A.union([1, 2, 3, 4], [3, 4, 5, 6]) // → [1, 2, 3, 4, 5, 6]
pipe([5, 2, 3, 5, 6], A.union([5, 2, 3, 1, 5, 4])) // → [5, 2, 3, 6, 1, 4]
uniq
Returns a new array containing only one copy of each element in the provided array.
function uniq<A>(xs: Array<A>): Array<A>
A.uniq([1, 2, 2, 3, 4, 4, 5, 6]) // → [1, 2, 3, 4, 5, 6,]
A.uniq([[1, 2], [2, 1], [1, 2], [3, 4]]) // → [[1, 2], [2, 1], [3, 4]]
A.uniq([
{ name: 'John', age: 20 },
{ name: 'Emily', age: 30 },
{ name: 'John', age: 20 },
]) // → [{ name: 'John', age: 20 }, { name: 'Emily', age: 30 }]
pipe([1, 2, 2, 3, 4, 4, 5, 6], A.uniq) // → [1, 2, 3, 4, 5, 6,]
uniqBy
Returns a new array containing only one copy of each element in the provided array, based upon the value returned by applying the function to each element.
function uniqBy<A, B>(xs: Array<A>, uniqFn: (_1: A) => B): Array<A>
function uniqBy<A, B>(uniqFn: (_1: A) => B): (xs: Array<A>) => Array<A>
A.uniqBy([1, 2, 2, 3, 4, 4, 5, 6], F.identity) // → [1, 2, 3, 4, 5, 6,]
A.uniqBy(
[
{ name: 'Joe', age: 20 },
{ name: 'John', age: 20 },
],
user => user.age,
) // → [{ name: 'Joe', age: 20 }]
pipe([1, 2, 2, 3, 4, 4, 5, 6], A.uniqBy(F.identity)) // → [1, 2, 3, 4, 5, 6,]
unzip
Takes an array of pairs and creates a pair of arrays. The first array contains all the first elements of the pairs and the other one contains all the second elements.
function unzip<A, B>(xs: Array<readonly [A, B]>): readonly [Array<A>, Array<B>]
updateAt
Creates a new array that replaces the value at the given index with the value returned by the provided function (the original array if the index is out of range).
function updateAt<A>(xs: Array<A>, targetIndex: number, fn: (_1: A) => A): Array<A>
function updateAt<A>(targetIndex: number, fn: (_1: A) => A): (xs: Array<A>) => Array<A>
zip
Creates a new array of pairs from corresponding elements of two provided arrays.
function zip<A, B>(xs1: Array<B>): (xs0: Array<A>) => Array<readonly [A, B]>
function zip<A, B>(xs0: Array<A>, xs1: Array<B>): Array<readonly [A, B]>
zipWith
Creates a new array by applying zipFn to corresponding elements of two provided arrays.
function zipWith<A, B, C>(xs0: Array<A>, xs1: Array<B>, zipFn: (_1: A, _2: B) => C): Array<C>
function zipWith<A, B, C>(xs1: Array<B>, zipFn: (_1: A, _2: B) => C): (xs0: Array<A>) => Array<C>
zipWithIndex
Creates a new array of each value paired with its index in a tuple.
function zipWithIndex<A>(xs: Array<A>): Array<readonly [A, number]>
A.zipWithIndex(['hello', 'world']) // → [['hello', 0], ['world', 1]]