// @flow // see https://gist.github.com/thecotne/6e5969f4aaf8f253985ed36b30ac9fe0 type $FlowGen$If = $Call< ((true, Then, Else) => Then) & ((false, Then, Else) => Else), X, Then, Else >; type $FlowGen$Assignable = $Call< ((...r: [B]) => true) & ((...r: [A]) => false), A >; import type { Option } from "../Option"; import type { ExtractNested } from "../types"; import type { Array } from "../types"; /** * Creates an empty array. Alternative for `const xs = [] as ReadonlyArray`. */ declare export function makeEmpty(): Array; /** * Returns a new array of size `n` populated by `mapFn(index)`, or an empty array if `n` is negative. */ declare export function makeWithIndex( n: number, mapFn: (_1: number) => A ): Array; declare export function makeWithIndex( mapFn: (_1: number) => A ): (n: number) => Array; /** * Returns a new array of size `n` populated by `element`, or an empty array if `n` is negative. */ declare export function make(n: number, element: A): Array; declare export function make(element: A): (n: number) => Array; /** * Alias for `make`. */ declare export function repeat(n: number, element: A): Array; declare export function repeat(element: A): (n: number) => Array; /** * Returns the size of the provided array. */ declare export function length(xs: Array): number; /** * Determines whether the given array is empty. */ declare export function isEmpty(xs: Array): boolean; /** * Determines whether the given array is not empty. */ declare export function isNotEmpty(xs: Array): boolean; /** * Returns a new array with the elements of the provided array in reverse order. */ declare export function reverse(xs: Array): Array; /** * Adds a single element to the end of an array. */ declare export function append(xs: Array, element: A): Array; declare export function append(element: A): (xs: Array) => Array; /** * Prepends a single element to the start of the given array. */ declare export function prepend(xs: Array, element: A): Array; declare export function prepend(element: A): (xs: Array) => Array; /** * Returns a new array which contains the given delimiter inserted before every element in the provided array. */ declare export function prependToAll(xs: Array, delimiter: A): Array; declare export function prependToAll( delimiter: A ): (xs: Array) => Array; /** * Creates a new array with the separator interposed between elements. */ declare export function intersperse(xs: Array, delimiter: A): Array; declare export function intersperse( delimiter: A ): (xs: Array) => Array; /** * Returns `Some(value)` at the given index, or `None` if the given index is out of range. */ declare export function get(xs: Array, index: number): Option; declare export function get(index: number): (xs: Array) => Option; /** * Alias for `get`. */ declare export function at(xs: Array, index: number): Option; declare export function at(index: number): (xs: Array) => Option; /** * Returns `value` at the given index (use only if you're entirely sure that a value exists at the given index). */ declare export function getUnsafe(xs: Array, index: number): A; declare export function getUnsafe(index: number): (xs: Array) => A; /** * Returns `value` at the given index, or `undefined` if the given index is out of range. */ declare export function getUndefined(xs: Array, index: number): A | void; declare export function getUndefined( index: number ): (xs: Array) => A | void; /** * Returns `Some(value)` for the first element in the array that satisifies the given predicate function, or `None` if no element satisifies the predicate. */ declare export function getBy( xs: Array, predicateFn: (_1: A) => boolean ): Option; declare export function getBy( predicateFn: (_1: A) => boolean ): (xs: Array) => Option; /** * Alias for `getBy`. */ declare export function find( xs: Array, predicateFn: (_1: A) => boolean ): Option; declare export function find( predicateFn: (_1: A) => boolean ): (xs: Array) => Option; /** * Returns `Some(value)` where `value` is the first element of the array, or `None` if the given array is empty. */ declare export function head(xs: Array): Option; /** * Returns the last element (`Some(value)`) in the array, or `None` if the given array is empty. */ declare export function last(xs: Array): Option; /** * 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). */ declare export function tail(xs: Array): Option>; /** * 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). */ declare export function tailOrEmpty(xs: Array): Array; /** * Returns a new array (`Some(xs)`) with all elements except the last of the provided array. */ declare export function init(xs: Array): Option>; /** * Returns a new array with all elements except the last of the provided array, or an empty array if the given array is empty. */ declare export function initOrEmpty(xs: Array): Array; /** * 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. */ declare export function take(xs: Array, n: number): Array; declare export function take(n: number): (xs: Array) => Array; /** * 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. */ declare export function takeExactly( xs: Array, n: number ): Option>; declare export function takeExactly( n: number ): (xs: Array) => Option>; /** * Returns a new array, filled with elements from the provided array until an element doesn't pass the provided predicate. */ declare export function takeWhile( xs: Array, predicateFn: (_1: A) => boolean ): Array; declare export function takeWhile( predicateFn: (_1: A) => boolean ): (xs: Array) => Array; /** * 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. */ declare export function drop(xs: Array, n: number): Array; declare export function drop(n: number): (xs: Array) => Array; /** * 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. */ declare export function dropExactly( xs: Array, n: number ): Option>; declare export function dropExactly( n: number ): (xs: Array) => Option>; /** * Drops elements from the beginning of the array until an element is reached which does not satisfy the given predicate. */ declare export function dropWhile( xs: Array, predicateFn: (_1: A) => boolean ): Array; declare export function dropWhile( predicateFn: (_1: A) => boolean ): (xs: Array) => Array; /** * Splits the provided array into head and tail parts (as a tuple), but only if the array is not empty. */ declare export function uncons(xs: Array): Option<[A, Array]>; /** * Returns a new array by calling `mapFn` for each element of the provided array. */ declare export function map(xs: Array, mapFn: (_1: A) => B): Array; declare export function map( mapFn: (_1: A) => B ): (xs: Array) => Array; /** * 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. */ declare export function mapWithIndex( xs: Array, mapFn: (_1: number, _2: A) => B ): Array; declare export function mapWithIndex( mapFn: (_1: number, _2: A) => B ): (xs: Array) => Array; /** * Returns a new array that keep all elements satisfy the given predicate. */ declare export function filter( xs: Array, predicateFn: (value: A) => boolean ): Array; declare export function filter( predicateFn: (value: A) => boolean ): (xs: Array) => Array; /** * Returns a new array that keep all elements satisfy the given predicate. */ declare export function filter( xs: Array, predicateFn: (value: A) => boolean ): Array; declare export function filter( predicateFn: (value: A) => boolean ): (xs: Array) => Array; /** * Alias for `filter`. */ declare export function keep( xs: Array, predicateFn: (value: A) => boolean ): Array; declare export function keep( predicateFn: (value: A) => boolean ): (xs: Array) => Array; /** * Alias for `filter`. */ declare export function keep( xs: Array, predicateFn: (value: A) => boolean ): Array; declare export function keep( predicateFn: (value: A) => boolean ): (xs: Array) => Array; /** * Returns a new array that keep all elements satisfy the given predicate (which take two arguments: the element for the array and its index). */ declare export function filterWithIndex( xs: Array, predicateFn: (index: number, value: A) => boolean ): Array; declare export function filterWithIndex( predicateFn: (index: number, value: A) => boolean ): (xs: Array) => Array; /** * Returns a new array that keep all elements satisfy the given predicate (which take two arguments: the element for the array and its index). */ declare export function filterWithIndex( xs: Array, predicateFn: (index: number, value: A) => boolean ): Array; declare export function filterWithIndex( predicateFn: (index: number, value: A) => boolean ): (xs: Array) => Array; /** * Alias for `filterWithIndex`. */ declare export function keepWithIndex( xs: Array, predicateFn: (index: number, value: A) => boolean ): Array; declare export function keepWithIndex( predicateFn: (index: number, value: A) => boolean ): (xs: Array) => Array; /** * Alias for `filterWithIndex`. */ declare export function keepWithIndex( xs: Array, predicateFn: (index: number, value: A) => boolean ): Array; declare export function keepWithIndex( predicateFn: (index: number, value: A) => boolean ): (xs: Array) => Array; /** * Returns a new array of elements from the provided array which do not satisfy the given predicate. */ declare export function reject( xs: Array, predicateFn: (_1: A) => boolean ): Array; declare export function reject( predicateFn: (_1: A) => boolean ): (xs: Array) => Array; /** * 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). */ declare export function rejectWithIndex( xs: Array, predicateFn: (_1: number, _2: A) => boolean ): Array; declare export function rejectWithIndex( predicateFn: (_1: number, _2: A) => boolean ): (xs: Array) => Array; /** * 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. */ declare export function reduce( xs: Array, initialValue: B, reduceFn: (_1: B, _2: A) => B ): B; declare export function reduce( initialValue: B, reduceFn: (_1: B, _2: A) => B ): (xs: Array) => B; /** * Works like A.reduce, except that the function `reduceFn` is applied to each item of `xs` from the last back to the first. */ declare export function reduceReverse( xs: Array, initialValue: B, reduceFn: (_1: B, _2: A) => B ): B; declare export function reduceReverse( initialValue: B, reduceFn: (_1: B, _2: A) => B ): (xs: Array) => B; /** * 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. */ declare export function reduceWithIndex( xs: Array, initialValue: B, reduceFn: (_1: B, _2: A, _3: number) => B ): B; declare export function reduceWithIndex( initialValue: B, reduceFn: (_1: B, _2: A, _3: number) => B ): (xs: Array) => B; /** * Returns two arrays (`Some([xs, ys])`), with the original array divided at the given index, or `None` if the index is out of range. */ declare export function splitAt( xs: Array, offset: number ): Option<[Array, Array]>; declare export function splitAt( offset: number ): (xs: Array) => Option<[Array, Array]>; /** * Returns an array of arrays, where each of the inner arrays has length equal to the provided `size` parameter. */ declare export function splitEvery( xs: Array, size: number ): Array>; declare export function splitEvery( size: number ): (xs: Array) => Array>; /** * Returns a new array with elements in the original array randomly shuffled. */ declare export function shuffle(xs: Array): Array; /** * 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. */ declare export function partition( xs: Array, predicateFn: (value: A) => boolean ): [Array, Array>]; declare export function partition( predicateFn: (value: A) => boolean ): (xs: Array) => [Array, Array>]; /** * 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. */ declare export function partition( xs: Array, predicateFn: (value: A) => boolean ): [Array, Array]; declare export function partition( predicateFn: (value: A) => boolean ): (xs: Array) => [Array, Array]; /** * Returns a new array containing the concatenation of two provided arrays. */ declare export function concat(xs1: Array): (xs0: Array) => Array; declare export function concat(xs0: Array, xs1: Array): Array; /** * Returns a new array as the concatenation of the provided array of arrays. */ declare export function concatMany(xs: Array>): Array; /** * Returns `true`` if all elements satisfy the given predicate. */ declare export function every(xs: Array, fn: (_1: A) => boolean): boolean; declare export function every( fn: (_1: A) => boolean ): (xs: Array) => boolean; /** * Returns `true` if at least one of the elements in the given array satifies the predicate. */ declare export function some(xs: Array, fn: (_1: A) => boolean): boolean; declare export function some( fn: (_1: A) => boolean ): (xs: Array) => boolean; /** * Returns a new array with the `len` elements of the given array starting at `offset` (offset can be negative). */ declare export function slice( xs: Array, offset: number, len: number ): Array; declare export function slice( offset: number, len: number ): (xs: Array) => Array; /** * Returns a new array with the elements of the given array starting at `offset` (offset can be negative). */ declare export function sliceToEnd(xs: Array, offset: number): Array; declare export function sliceToEnd( offset: number ): (xs: Array) => Array; /** * Returns `false` if length of both arrays is not the same, otherwise compares elements one by one using the comparator. */ declare export function eq( xs0: Array, xs1: Array, comparatorFn: (_1: A, _2: A) => boolean ): boolean; declare export function eq( xs1: Array, comparatorFn: (_1: A, _2: A) => boolean ): (xs0: Array) => boolean; /** * Returns a new array of numbers from `start` (inclusive) to `finish` (exclusive). */ declare export function range(finish: number): (start: number) => Array; declare export function range(start: number, finish: number): Array; /** * Returns a new array of numbers from `start` (inclusive) to `finish` (exclusive). */ declare export function rangeBy( finish: number, step: number ): (start: number) => Array; declare export function rangeBy( start: number, finish: number, step: number ): Array; /** * Returns a copy of the provided array. */ declare export function copy(xs: Array): Array; /** * Creates a new array of pairs from corresponding elements of two provided arrays. */ declare export function zip( xs1: Array ): (xs0: Array) => Array<[A, B]>; declare export function zip(xs0: Array, xs1: Array): Array<[A, B]>; /** * Creates a new array by applying `zipFn` to corresponding elements of two provided arrays. */ declare export function zipWith( xs0: Array, xs1: Array, zipFn: (_1: A, _2: B) => C ): Array; declare export function zipWith( xs1: Array, zipFn: (_1: A, _2: B) => C ): (xs0: Array) => Array; /** * 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. */ declare export function unzip(xs: Array<[A, B]>): [Array, Array]; /** * 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). */ declare export function replaceAt( xs: Array, targetIndex: number, element: A ): Array; declare export function replaceAt( targetIndex: number, element: A ): (xs: Array) => Array; /** * Creates a new array that inserts the given value at the given index (no insertion is made if the index is out of range). */ declare export function insertAt( xs: Array, targetIndex: number, element: A ): Array; declare export function insertAt( targetIndex: number, element: A ): (xs: Array) => Array; /** * 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). */ declare export function updateAt( xs: Array, targetIndex: number, fn: (_1: A) => A ): Array; declare export function updateAt( targetIndex: number, fn: (_1: A) => A ): (xs: Array) => Array; /** * Creates a new array with the elements at the two given indexes swapped (the original array if the index is out of range). */ declare export function swapAt( xs: Array, targetIndex: number, swapIndex: number ): Array; declare export function swapAt( targetIndex: number, swapIndex: number ): (xs: Array) => Array; /** * Creates a new array without the element at the given index (the original array if the index is out of range). */ declare export function removeAt( xs: Array, targetIndex: number ): Array; declare export function removeAt( targetIndex: number ): (xs: Array) => Array; /** * 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. */ declare export function uniqBy( xs: Array, uniqFn: (_1: A) => B ): Array; declare export function uniqBy( uniqFn: (_1: A) => B ): (xs: Array) => Array; /** * Returns a new array containing only one copy of each element in the provided array. */ declare export function uniq(xs: Array): Array; /** * Calls `fn` on each element of the provided array. */ declare export function forEach(xs: Array, fn: (_1: A) => void): void; declare export function forEach(fn: (_1: A) => void): (xs: Array) => void; /** * Calls `fn` (which takes two arguments: the element from array and its index) on each element of the provided array. */ declare export function forEachWithIndex( xs: Array, fn: (_1: number, _2: A) => void ): void; declare export function forEachWithIndex( fn: (_1: number, _2: A) => void ): (xs: Array) => void; /** * Returns `Some(index)` for the first value in the provided array that satisifies the predicate function. */ declare export function getIndexBy( xs: Array, predicateFn: (_1: A) => boolean ): Option; declare export function getIndexBy( predicateFn: (_1: A) => boolean ): (xs: Array) => Option; /** * Returns `true` if the provided value is equal to at least one element of the given array. */ declare export function includes(xs: Array, value: A): boolean; declare export function includes(value: A): (xs: Array) => boolean; /** * Converts each element of the array to a string and concatenates them, separated by the given string. */ declare export function join(xs: Array, delimiter: string): string; declare export function join(delimiter: string): (xs: Array) => string; /** * Returns a new array, sorted according to the comparator function. */ declare export function sort( xs: Array, sortFn: (_1: A, _2: A) => number ): Array; declare export function sort( sortFn: (_1: A, _2: A) => number ): (xs: Array) => Array; /** * Returns a new array, sorted according to the provided function. */ declare export function sortBy( xs: Array, sortFn: (_1: A) => B ): Array; declare export function sortBy( sortFn: (_1: A) => B ): (xs: Array) => Array; /** * Splits the given array into sub-arrays in an object, grouped by the result of running each value through the provided function. */ declare export function groupBy( xs: Array, groupFn: (item: A) => B ): $Rest<{ [key: B]: [A] & A[], ... }, { ... }>; declare export function groupBy( groupFn: (item: A) => B ): (xs: Array) => $Rest<{ [key: B]: [A] & A[], ... }, { ... }>; /** * Creates a new array with all sub-array elements concatenated into it (the single level depth). */ declare export function flat( xs: Array ): Array<$FlowGen$If<$FlowGen$Assignable>, B, A>>; /** * Creates a new array with all sub-array elements concatenated into it recursively up to the `Infinite` depth. */ declare export function deepFlat(xs: Array): Array>; /** * Converts the given array to the TypeScript's tuple. */ declare export function toTuple>(xs: [] & T): [] & T; /** * Applies a side-effect function on each element of the provided array. */ declare export function tap(xs: Array, fn: (_1: A) => void): Array; declare export function tap(fn: (_1: A) => void): (xs: Array) => Array; /** * Returns a new tuple with the reverse order of the elements. */ declare export function flip(xs: [A, B]): [B, A]; /** * Returns a new array that keep all elements that return `Some(value)` applied within `predicateFn`. */ declare export function filterMap( xs: Array, predicateFn: (_1: A) => Option ): Array; declare export function filterMap( predicateFn: (_1: A) => Option ): (xs: Array) => Array; /** * Alias for `filterMap`. */ declare export function keepMap( xs: Array, predicateFn: (_1: A) => Option ): Array; declare export function keepMap( predicateFn: (_1: A) => Option ): (xs: Array) => Array; /** * Removes the first occurrence of the given value from the array, using the given equality function. */ declare export function removeFirstBy( xs: Array, value: B, predicateFn: (_1: A, _2: B) => boolean ): Array; declare export function removeFirstBy( value: B, predicateFn: (_1: A, _2: B) => boolean ): (xs: Array) => Array; /** * Creates a copy of the given array with the first occurrence of the given element removed */ declare export function removeFirst(xs: Array, value: A): Array; declare export function removeFirst(value: A): (xs: Array) => Array; /** * Creates a new array of each value paired with its index in a tuple. */ declare export function zipWithIndex(xs: Array): Array<[A, number]>; /** * Returns `true` if all elements of the array match the predicate function, otherwise, returns `false`. */ declare export function all( xs: Array, predicateFn: (_1: A) => boolean ): boolean; declare export function all( predicateFn: (_1: A) => boolean ): (xs: Array) => boolean; /** * Returns `true` if at least one of the elements of the array match the predicate function, otherwise, returns `false`. */ declare export function any( xs: Array, predicateFn: (_1: A) => boolean ): boolean; declare export function any( predicateFn: (_1: A) => boolean ): (xs: Array) => boolean; /** * Returns elements from the first array, not existing in the second array. */ declare export function difference(ys: Array): (xs: Array) => Array; declare export function difference(xs: Array, ys: Array): Array; /** * Returns union of two arrays. */ declare export function union(ys: Array): (xs: Array) => Array; declare export function union(xs: Array, ys: Array): Array; /** * Returns intersection of two arrays. */ declare export function intersection( ys: Array ): (xs: Array) => Array; declare export function intersection(xs: Array, ys: Array): Array;