fp-ts-std
Version:
The missing pseudo-standard library for fp-ts.
713 lines • 26.1 kB
TypeScript
/**
* Various functions to aid in working with readonly arrays.
*
* @since 0.10.0
*/
import type { Applicative, Applicative1, Applicative2, Applicative2C, Applicative3, Applicative4 } from "fp-ts/Applicative";
import type { Either } from "fp-ts/Either";
import type { Endomorphism } from "fp-ts/Endomorphism";
import type { Eq } from "fp-ts/Eq";
import type { HKT, Kind, Kind2, Kind3, Kind4, URIS, URIS2, URIS3, URIS4 } from "fp-ts/HKT";
import type { Monad1, Monad2, Monad2C, Monad3, Monad3C, Monad4 } from "fp-ts/Monad";
import type { Option } from "fp-ts/Option";
import type { Ord } from "fp-ts/Ord";
import { type Predicate } from "fp-ts/Predicate";
import type { ReadonlyNonEmptyArray } from "fp-ts/ReadonlyNonEmptyArray";
import type { These } from "fp-ts/These";
/**
* Like `fp-ts/ReadonlyArray::elem` but flipped, which the "V" suffix denotes.
*
* @example
* import { elemV } from 'fp-ts-std/ReadonlyArray'
* import { eqString } from 'fp-ts/Eq'
*
* const isLowerVowel = elemV(eqString)(['a', 'e', 'i', 'o', 'u'])
*
* assert.strictEqual(isLowerVowel('a'), true)
* assert.strictEqual(isLowerVowel('b'), false)
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const elemV: <A>(eq: Eq<A>) => (xs: readonly A[]) => Predicate<A>;
/**
* Check if a predicate does not hold for any array member.
*
* @example
* import { none } from 'fp-ts-std/ReadonlyArray'
* import { Predicate } from 'fp-ts/Predicate'
*
* const isFive: Predicate<number> = n => n === 5
* const noneAreFive = none(isFive)
*
* assert.strictEqual(noneAreFive([4, 4, 4]), true)
* assert.strictEqual(noneAreFive([4, 5, 4]), false)
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const none: <A>(f: Predicate<A>) => Predicate<ReadonlyArray<A>>;
/**
* Join an array of strings together into a single string using the supplied
* separator.
*
* @example
* import { join } from 'fp-ts-std/ReadonlyArray'
*
* const commaSepd = join(',')
*
* assert.strictEqual(commaSepd([]), '')
* assert.strictEqual(commaSepd(['a']), 'a')
* assert.strictEqual(commaSepd(['a', 'b', 'c']), 'a,b,c')
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const join: (x: string) => (ys: ReadonlyArray<string>) => string;
/**
* Like `fp-ts/Array::getEq`, but items are not required to be in the same
* order to determine equivalence. This function is therefore less efficient,
* and `getEq` should be preferred on ordered data.
*
* @example
* import { getEq } from 'fp-ts/Array'
* import { getDisorderedEq } from 'fp-ts-std/ReadonlyArray'
* import { ordNumber } from 'fp-ts/Ord'
*
* const f = getEq(ordNumber)
* const g = getDisorderedEq(ordNumber)
*
* assert.strictEqual(f.equals([1, 2, 3], [1, 3, 2]), false)
* assert.strictEqual(g.equals([1, 2, 3], [1, 3, 2]), true)
*
* @category 1 Typeclass Instances
* @since 0.10.0
*/
export declare const getDisorderedEq: <A>(ordA: Ord<A>) => Eq<readonly A[]>;
/**
* Pluck the first item out of an array matching a predicate. Any further
* matches will be left untouched.
*
* This can be thought of as analagous to `fp-ts/Array::findFirst` where
* the remaining items, sans the match (if any), are returned as well.
*
* @example
* import { pluckFirst } from 'fp-ts-std/ReadonlyArray'
* import * as O from 'fp-ts/Option'
* import { Predicate } from 'fp-ts/Predicate'
*
* const isOverFive: Predicate<number> = n => n > 5
* const pluckFirstOverFive = pluckFirst(isOverFive)
*
* assert.deepStrictEqual(pluckFirstOverFive([1, 3, 5]), [O.none, [1, 3, 5]])
* assert.deepStrictEqual(pluckFirstOverFive([1, 3, 5, 7, 9]), [O.some(7), [1, 3, 5, 9]])
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const pluckFirst: <A>(p: Predicate<A>) => (xs: readonly A[]) => [Option<A>, readonly A[]];
/**
* Update an item in an array or, if it's not present yet, insert it.
*
* If the item exists more than once (as determined by the supplied `Eq`
* instance), only the first to be found will be updated. The order in which
* the array is checked is unspecified.
*
* @example
* import { upsert } from 'fp-ts-std/ReadonlyArray'
* import { eqString, contramap } from 'fp-ts/Eq'
*
* type Account = {
* id: string
* name: string
* }
*
* const eqAccount = contramap<string, Account>(acc => acc.id)(eqString)
*
* const accounts: ReadonlyArray<Account> = [{
* id: 'a',
* name: 'an account',
* }, {
* id: 'b',
* name: 'another account',
* }]
*
* const created: Account = {
* id: 'c',
* name: 'yet another account',
* }
*
* const updated: Account = {
* id: 'b',
* name: 'renamed account name',
* }
*
* const upsertAccount = upsert(eqAccount)
*
* assert.deepStrictEqual(upsertAccount(created)(accounts), [accounts[0], accounts[1], created])
* assert.deepStrictEqual(upsertAccount(updated)(accounts), [accounts[0], updated])
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const upsert: <A>(eqA: Eq<A>) => (x: A) => (ys: readonly A[]) => ReadonlyNonEmptyArray<A>;
/**
* Insert all the elements of an array into another array at the specified
* index. Returns `None` if the index is out of bounds.
*
* The array of elements to insert must be non-empty.
*
* @example
* import { insertMany } from 'fp-ts-std/ReadonlyArray'
* import * as O from 'fp-ts/Option'
*
* const f = insertMany(1)(['a', 'b'])
* assert.deepStrictEqual(f([]), O.none)
* assert.deepStrictEqual(f(['x']), O.some(['x', 'a', 'b']))
* assert.deepStrictEqual(f(['x', 'y']), O.some(['x', 'a', 'b', 'y']))
*
* @category 3 Functions
* @since 0.5.0
*/
export declare const insertMany: (i: number) => <A>(xs: ReadonlyNonEmptyArray<A>) => (ys: readonly A[]) => Option<ReadonlyNonEmptyArray<A>>;
/**
* Filter a list, removing any elements that repeat that directly precede them.
*
* @example
* import { dropRepeats } from 'fp-ts-std/ReadonlyArray'
* import { eqNumber } from 'fp-ts/Eq'
*
* assert.deepStrictEqual(dropRepeats(eqNumber)([1, 2, 2, 3, 2, 4, 4]), [1, 2, 3, 2, 4])
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const dropRepeats: <A>(eq: Eq<A>) => Endomorphism<ReadonlyArray<A>>;
/**
* Check if an array starts with the specified subarray.
*
* @example
* import { startsWith } from 'fp-ts-std/ReadonlyArray'
* import { eqString } from 'fp-ts/Eq'
*
* const startsXyz = startsWith(eqString)(['x', 'y', 'z'])
*
* assert.strictEqual(startsXyz(['x', 'y', 'z', 'a']), true)
* assert.strictEqual(startsXyz(['a', 'x', 'y', 'z']), false)
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const startsWith: <A>(eq: Eq<A>) => (start: readonly A[]) => Predicate<readonly A[]>;
/**
* Check if an array ends with the specified subarray.
*
* @example
* import { endsWith } from 'fp-ts-std/ReadonlyArray'
* import { eqString } from 'fp-ts/Eq'
*
* const endsXyz = endsWith(eqString)(['x', 'y', 'z'])
*
* assert.strictEqual(endsXyz(['a', 'x', 'y', 'z']), true)
* assert.strictEqual(endsXyz(['a', 'x', 'b', 'z']), false)
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const endsWith: <A>(eq: Eq<A>) => (end: readonly A[]) => Predicate<readonly A[]>;
/**
* Returns a new array without the values present in the first input array.
*
* @example
* import { without } from 'fp-ts-std/ReadonlyArray'
* import { eqNumber } from 'fp-ts/Eq'
*
* const withoutFourOrFive = without(eqNumber)([4, 5])
*
* assert.deepStrictEqual(withoutFourOrFive([3, 4]), [3])
* assert.deepStrictEqual(withoutFourOrFive([4, 5]), [])
* assert.deepStrictEqual(withoutFourOrFive([4, 5, 6]), [6])
* assert.deepStrictEqual(withoutFourOrFive([3, 4, 5, 6]), [3, 6])
* assert.deepStrictEqual(withoutFourOrFive([4, 3, 4, 5, 6, 5]), [3, 6])
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const without: <A>(eq: Eq<A>) => (xs: readonly A[]) => Endomorphism<readonly A[]>;
/**
* Returns the {@link https://en.wikipedia.org/wiki/Cartesian_product Cartesian product}
* of two arrays. In other words, returns an array containing tuples of every
* possible ordered combination of the two input arrays.
*
* @example
* import { cartesian } from 'fp-ts-std/ReadonlyArray'
*
* assert.deepStrictEqual(
* cartesian([1, 2])(['a', 'b', 'c']),
* [[1, 'a'], [1, 'b'], [1, 'c'], [2, 'a'], [2, 'b'], [2, 'c']],
* )
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const cartesian: <A>(xs: readonly A[]) => <B>(ys: readonly B[]) => readonly [A, B][];
/**
* Adds together all the numbers in the input array.
*
* @example
* import { sum } from 'fp-ts-std/ReadonlyArray'
*
* assert.strictEqual(sum([]), 0)
* assert.strictEqual(sum([25, 3, 10]), 38)
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const sum: (xs: ReadonlyArray<number>) => number;
/**
* Multiplies together all the numbers in the input array.
*
* @example
* import { product } from 'fp-ts-std/ReadonlyArray'
*
* assert.strictEqual(product([]), 1)
* assert.strictEqual(product([5]), 5)
* assert.strictEqual(product([4, 2, 3]), 24)
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const product: (xs: ReadonlyArray<number>) => number;
/**
* Calculate the mean of an array of numbers.
*
* @example
* import { mean } from 'fp-ts-std/ReadonlyArray'
*
* assert.deepStrictEqual(mean([2, 7, 9]), 6)
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const mean: (xs: ReadonlyNonEmptyArray<number>) => number;
/**
* Calculate the median of an array of numbers.
*
* @example
* import { median } from 'fp-ts-std/ReadonlyArray'
*
* assert.deepStrictEqual(median([2, 9, 7]), 7)
* assert.deepStrictEqual(median([7, 2, 10, 9]), 8)
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const median: (xs: ReadonlyNonEmptyArray<number>) => number;
/**
* Returns an array of tuples of the specified length occupied by consecutive
* elements.
*
* If `n` is not a positive number, an empty array is returned.
*
* If `n` is greater than the length of the array, an empty array is returned.
*
* @example
* import { aperture } from 'fp-ts-std/ReadonlyArray'
*
* assert.deepStrictEqual(aperture(1)([1, 2, 3, 4]), [[1], [2], [3], [4]])
* assert.deepStrictEqual(aperture(2)([1, 2, 3, 4]), [[1, 2], [2, 3], [3, 4]])
* assert.deepStrictEqual(aperture(3)([1, 2, 3, 4]), [[1, 2, 3], [2, 3, 4]])
* assert.deepStrictEqual(aperture(4)([1, 2, 3, 4]), [[1, 2, 3, 4]])
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const aperture: (n: number) => <A>(xs: readonly A[]) => readonly (readonly A[])[];
/**
* Returns the elements of the array between the start index (inclusive) and the
* end index (exclusive).
*
* This is merely a functional wrapper around `Array.prototype.slice`.
*
* @example
* import { slice } from 'fp-ts-std/ReadonlyArray'
*
* const xs = ['a', 'b', 'c', 'd']
*
* assert.deepStrictEqual(slice(1)(3)(xs), ['b', 'c'])
* assert.deepStrictEqual(slice(1)(Infinity)(xs), ['b', 'c', 'd'])
* assert.deepStrictEqual(slice(0)(-1)(xs), ['a', 'b', 'c'])
* assert.deepStrictEqual(slice(-3)(-1)(xs), ['b', 'c'])
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const slice: (start: number) => (end: number) => <A>(xs: readonly A[]) => readonly A[];
/**
* Filters out items in the array for which the predicate holds. This can be
* thought of as the inverse of ordinary array filtering.
*
* @example
* import { reject } from 'fp-ts-std/ReadonlyArray'
* import { Predicate } from 'fp-ts/Predicate'
*
* const isEven: Predicate<number> = n => n % 2 === 0
*
* assert.deepStrictEqual(reject(isEven)([1, 2, 3, 4]), [1, 3])
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const reject: <A>(f: Predicate<A>) => <B extends A>(xs: readonly B[]) => readonly B[];
/**
* Move an item at index `from` to index `to`. See also `moveTo`.
*
* If either index is out of bounds, `None` is returned.
*
* If both indices are the same, the array is returned unchanged.
*
* @example
* import { moveFrom } from 'fp-ts-std/ReadonlyArray'
* import * as O from 'fp-ts/Option'
*
* assert.deepStrictEqual(moveFrom(0)(1)(['a', 'b', 'c']), O.some(['b', 'a', 'c']))
* assert.deepStrictEqual(moveFrom(1)(1)(['a', 'b', 'c']), O.some(['a', 'b', 'c']))
* assert.deepStrictEqual(moveFrom(0)(0)([]), O.none)
* assert.deepStrictEqual(moveFrom(0)(1)(['a']), O.none)
* assert.deepStrictEqual(moveFrom(1)(0)(['a']), O.none)
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const moveFrom: (from: number) => (to: number) => <A>(xs: readonly A[]) => Option<readonly A[]>;
/**
* Move an item at index `from` to index `to`. See also `moveFrom`.
*
* If either index is out of bounds, `None` is returned.
*
* If both indices are the same, the array is returned unchanged.
*
* @example
* import { moveTo } from 'fp-ts-std/ReadonlyArray'
* import * as O from 'fp-ts/Option'
*
* assert.deepStrictEqual(moveTo(1)(0)(['a', 'b', 'c']), O.some(['b', 'a', 'c']))
* assert.deepStrictEqual(moveTo(1)(1)(['a', 'b', 'c']), O.some(['a', 'b', 'c']))
* assert.deepStrictEqual(moveTo(0)(0)([]), O.none)
* assert.deepStrictEqual(moveTo(0)(1)(['a']), O.none)
* assert.deepStrictEqual(moveTo(1)(0)(['a']), O.none)
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const moveTo: (b: number) => (a: number) => <A>(xs: readonly A[]) => Option<readonly A[]>;
/**
* Map each item of an array to a key, and count how many map to each key.
*
* @example
* import { countBy } from 'fp-ts-std/ReadonlyArray'
* import * as S from 'fp-ts/string'
*
* const f = countBy(S.toLowerCase)
* const xs = ['A', 'b', 'C', 'a', 'e', 'A']
*
* assert.deepStrictEqual(f(xs), { a: 3, b: 1, c: 1, e: 1 })
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const countBy: <A>(f: (x: A) => string) => (xs: readonly A[]) => Record<string, number>;
/**
* Remove the longest initial subarray from the end of the input array for
* which all elements satisfy the specified predicate, creating a new array.
*
* @example
* import { dropRightWhile } from 'fp-ts-std/ReadonlyArray'
* import { Predicate } from 'fp-ts/Predicate'
*
* const isEven: Predicate<number> = n => n % 2 === 0
* const dropRightEvens = dropRightWhile(isEven)
*
* assert.deepStrictEqual(dropRightEvens([6, 7, 3, 4, 2]), [6, 7, 3])
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const dropRightWhile: <A>(f: Predicate<A>) => <B extends A>(xs: readonly B[]) => readonly B[];
/**
* Drop a number of elements from the specified index an array, returning a
* new array.
*
* If `i` is out of bounds, `None` will be returned.
*
* If `i` is a float, it will be rounded down to the nearest integer.
*
* If `n` is larger than the available number of elements from the provided
* index, only the elements prior to said index will be returned.
*
* If `n` is not a positive number, the array will be returned whole.
*
* If `n` is a float, it will be rounded down to the nearest integer.
*
* @example
* import { dropAt } from 'fp-ts-std/ReadonlyArray'
* import * as O from 'fp-ts/Option'
*
* assert.deepStrictEqual(dropAt(2)(0)(['a', 'b', 'c', 'd', 'e', 'f', 'g']), O.some(['a', 'b', 'c', 'd', 'e', 'f', 'g']))
* assert.deepStrictEqual(dropAt(2)(3)(['a', 'b', 'c', 'd', 'e', 'f', 'g']), O.some(['a', 'b', 'f', 'g']))
* assert.deepStrictEqual(dropAt(2)(Infinity)(['a', 'b', 'c', 'd', 'e', 'f', 'g']), O.some(['a', 'b']))
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const dropAt: (i: number) => (n: number) => <A>(xs: readonly A[]) => Option<readonly A[]>;
/**
* Tranposes the rows and columns of a 2D list. If some of the rows are shorter
* than the following rows, their elements are skipped.
*
* @example
* import { transpose } from 'fp-ts-std/ReadonlyArray'
*
* assert.deepStrictEqual(transpose([[1, 2, 3], [4, 5, 6]]), [[1, 4], [2, 5], [3, 6]])
* assert.deepStrictEqual(transpose([[1, 4], [2, 5], [3, 6]]), [[1, 2, 3], [4, 5, 6]])
* assert.deepStrictEqual(transpose([[10, 11], [20], [], [30, 31,32]]), [[10, 20, 30], [11, 31], [32]])
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const transpose: <A>(xs: readonly (readonly A[])[]) => readonly (readonly A[])[];
/**
* Calculate the longest initial subarray from the end of the input array for
* which all elements satisfy the specified predicate, creating a new array.
*
* @example
* import { takeRightWhile } from 'fp-ts-std/ReadonlyArray'
* import { Predicate } from 'fp-ts/Predicate'
*
* const isEven: Predicate<number> = n => n % 2 === 0
* const takeRightEvens = takeRightWhile(isEven)
*
* assert.deepStrictEqual(takeRightEvens([6, 7, 3, 4, 2]), [4, 2])
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const takeRightWhile: <A>(f: Predicate<A>) => <B extends A>(xs: readonly B[]) => readonly B[];
/**
* Creates an array of all values which are present in one of the two input
* arrays, but not both. The order is determined by the input arrays and
* duplicate values present only in one input array are maintained.
*
* @example
* import { symmetricDifference } from 'fp-ts-std/ReadonlyArray'
* import { eqNumber } from 'fp-ts/Eq'
*
* assert.deepStrictEqual(symmetricDifference(eqNumber)([1, 2, 3, 4])([3, 4, 5, 6]), [1, 2, 5, 6])
* assert.deepStrictEqual(symmetricDifference(eqNumber)([1, 7, 7, 4, 3])([3, 4, 9, 6]), [1, 7, 7, 9, 6])
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const symmetricDifference: <A>(eq: Eq<A>) => (xs: readonly A[]) => Endomorphism<readonly A[]>;
/**
* Like ordinary array reduction, however this also takes a predicate that is
* evaluated before each step. If the predicate doesn't hold, the reduction
* short-circuits and returns the current accumulator value.
*
* @example
* import { reduceWhile } from 'fp-ts-std/ReadonlyArray'
* import { add } from 'fp-ts-std/Number'
* import { Predicate } from 'fp-ts/Predicate'
*
* const isEven: Predicate<number> = n => n % 2 === 0
* const reduceUntilOdd = reduceWhile(isEven)
*
* assert.strictEqual(reduceUntilOdd(add)(0)([2, 4, 6, 9, 10]), 12)
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const reduceWhile: <A>(p: Predicate<A>) => <B>(f: (x: A) => (y: B) => B) => (x: B) => (ys: readonly A[]) => B;
/**
* Like ordinary array reduction, however this also takes a predicate that is
* evaluated before each step. If the predicate doesn't hold, the reduction
* short-circuits and returns the current accumulator value.
*
* @example
* import { reduceRightWhile } from 'fp-ts-std/ReadonlyArray'
* import { add } from 'fp-ts-std/Number'
* import { Predicate } from 'fp-ts/Predicate'
*
* const isEven: Predicate<number> = n => n % 2 === 0
* const reduceRightUntilOdd = reduceRightWhile(isEven)
*
* assert.strictEqual(reduceRightUntilOdd(add)(0)([2, 4, 7, 8, 10]), 18)
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const reduceRightWhile: <A>(p: Predicate<A>) => <B>(f: (x: A) => (y: B) => B) => (x: B) => (ys: readonly A[]) => B;
/**
* Obtain the minimum value from a non-empty array.
*
* @example
* import { minimum } from 'fp-ts-std/ReadonlyArray'
* import { ordNumber } from 'fp-ts/Ord'
*
* assert.strictEqual(minimum(ordNumber)([2, 3, 1, 5, 4]), 1)
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const minimum: <A>(ord: Ord<A>) => (xs: ReadonlyNonEmptyArray<A>) => A;
/**
* Obtain the maximum value from a non-empty array.
*
* @example
* import { maximum } from 'fp-ts-std/ReadonlyArray'
* import { ordNumber } from 'fp-ts/Ord'
*
* assert.strictEqual(maximum(ordNumber)([2, 3, 1, 5, 4]), 5)
*
* @category 3 Functions
* @since 0.10.0
*/
export declare const maximum: <A>(ord: Ord<A>) => (xs: ReadonlyNonEmptyArray<A>) => A;
/**
* Greedy zip, preserving all items and expressing the possibility of unequal
* input sizes via the `These` type.
*
* @example
* import { zipAll } from 'fp-ts-std/ReadonlyArray'
* import * as T from 'fp-ts/These'
*
* assert.deepStrictEqual(zipAll([3, 4, 5, 6])([1, 2]), [T.both(1, 3), T.both(2, 4), T.right(5), T.right(6)])
*
* @category 3 Functions
* @since 0.11.0
*/
export declare const zipAll: <A>(xs: readonly A[]) => <B>(ys: readonly B[]) => readonly These<B, A>[];
/**
* Filter an array based upon a predicate whose boolean is returned in an
* applicative context. This can be helpful if your predicate is asynchronous
* and therefore `Task`-based, for example.
*
* @example
* import * as T from "fp-ts/Task"
* import { Task } from "fp-ts/Task"
* import { filterA } from "fp-ts-std/ReadonlyArray"
*
* const asyncIsEven = (n: number): Task<boolean> => T.of(n % 2 === 0)
*
* filterA(T.ApplicativePar)(asyncIsEven)([1, 2, 3, 4, 5])().then((xs) => {
* assert.deepStrictEqual(xs, [2, 4])
* })
*
* @category 2 Typeclass Methods
* @since 0.12.0
*/
export declare function filterA<F extends URIS4>(F: Applicative4<F>): <S, R, E, A>(p: (x: A) => Kind4<F, S, R, E, boolean>) => (xs: ReadonlyArray<A>) => Kind4<F, S, R, E, ReadonlyArray<A>>;
export declare function filterA<F extends URIS3>(F: Applicative3<F>): <R, E, A>(p: (x: A) => Kind3<F, R, E, boolean>) => (xs: ReadonlyArray<A>) => Kind3<F, R, E, ReadonlyArray<A>>;
export declare function filterA<F extends URIS2>(F: Applicative2<F>): <E, A>(p: (x: A) => Kind2<F, E, boolean>) => (xs: ReadonlyArray<A>) => Kind2<F, E, ReadonlyArray<A>>;
export declare function filterA<F extends URIS2, E>(F: Applicative2C<F, E>): <A>(p: (x: A) => Kind2<F, E, boolean>) => (xs: ReadonlyArray<A>) => Kind2<F, E, ReadonlyArray<A>>;
export declare function filterA<F extends URIS>(F: Applicative1<F>): <A>(p: (x: A) => Kind<F, boolean>) => (xs: ReadonlyArray<A>) => Kind<F, ReadonlyArray<A>>;
export declare function filterA<F>(F: Applicative<F>): <A>(p: (x: A) => HKT<F, boolean>) => (xs: ReadonlyArray<A>) => HKT<F, ReadonlyArray<A>>;
/**
* Remove the element at the specified index, returning both said element and
* the remaining array. Returns `None` if the index is out of bounds.
*
* @example
* import { extractAt } from 'fp-ts-std/ReadonlyArray'
* import * as O from 'fp-ts/Option'
*
* const f = extractAt(1)
* assert.deepStrictEqual(f(['x']), O.none)
* assert.deepStrictEqual(f(['x', 'y']), O.some(['y', ['x']]))
* assert.deepStrictEqual(f(['x', 'y', 'z']), O.some(['y', ['x', 'z']]))
*
* @category 3 Functions
* @since 0.12.0
*/
export declare const extractAt: (i: number) => <A>(xs: readonly A[]) => Option<[A, readonly A[]]>;
/**
* Convert an `Iterable` to a `ReadonlyArray`.
*
* @example
* import { fromIterable } from 'fp-ts-std/ReadonlyArray'
*
* assert.deepStrictEqual(fromIterable('hello'), ['h', 'e', 'l', 'l', 'o'])
*
* @category 3 Functions
* @since 0.14.0
*/
export declare const fromIterable: <A>(xs: Iterable<A>) => ReadonlyArray<A>;
/**
* Fold a readonly array of monadic booleans from left-to-right in terms of &&.
* Short-circuits.
*
* @example
* import { allM } from 'fp-ts-std/ReadonlyArray'
* import * as IO from 'fp-ts/IO'
* import { execute } from 'fp-ts-std/IO'
*
* const f = allM(IO.Monad)
*
* assert.strictEqual(execute(f([IO.of(true), IO.of(true), IO.of(true)])), true)
* assert.strictEqual(execute(f([IO.of(true), IO.of(false), IO.of(true)])), false)
*
* @category 2 Typeclass Methods
* @since 0.15.0
*/
export declare function allM<M extends URIS4>(M: Monad4<M>): <S, R, E>(xs: ReadonlyArray<Kind4<M, S, R, E, boolean>>) => Kind4<M, S, R, E, boolean>;
export declare function allM<M extends URIS3>(M: Monad3<M>): <R, E>(xs: ReadonlyArray<Kind3<M, R, E, boolean>>) => Kind3<M, R, E, boolean>;
export declare function allM<M extends URIS3, E>(M: Monad3C<M, E>): <R>(xs: ReadonlyArray<Kind3<M, R, E, boolean>>) => Kind3<M, R, E, boolean>;
export declare function allM<M extends URIS2>(M: Monad2<M>): <E>(xs: ReadonlyArray<Kind2<M, E, boolean>>) => Kind2<M, E, boolean>;
export declare function allM<M extends URIS2, E>(M: Monad2C<M, E>): (xs: ReadonlyArray<Kind2<M, E, boolean>>) => Kind2<M, E, boolean>;
export declare function allM<M extends URIS>(M: Monad1<M>): (xs: ReadonlyArray<Kind<M, boolean>>) => Kind<M, boolean>;
/**
* Fold an array of monadic booleans from left-to-right in terms of ||.
* Short-circuits.
*
* @example
* import { anyM } from 'fp-ts-std/ReadonlyArray'
* import * as IO from 'fp-ts/IO'
* import { execute } from 'fp-ts-std/IO'
*
* const f = anyM(IO.Monad)
*
* assert.strictEqual(execute(f([IO.of(false), IO.of(false), IO.of(false)])), false)
* assert.strictEqual(execute(f([IO.of(false), IO.of(true), IO.of(false)])), true)
*
* @category 2 Typeclass Methods
* @since 0.15.0
*/
export declare function anyM<M extends URIS4>(M: Monad4<M>): <S, R, E>(xs: ReadonlyArray<Kind4<M, S, R, E, boolean>>) => Kind4<M, S, R, E, boolean>;
export declare function anyM<M extends URIS3>(M: Monad3<M>): <R, E>(xs: ReadonlyArray<Kind3<M, R, E, boolean>>) => Kind3<M, R, E, boolean>;
export declare function anyM<M extends URIS3, E>(M: Monad3C<M, E>): <R>(xs: ReadonlyArray<Kind3<M, R, E, boolean>>) => Kind3<M, R, E, boolean>;
export declare function anyM<M extends URIS2>(M: Monad2<M>): <E>(xs: ReadonlyArray<Kind2<M, E, boolean>>) => Kind2<M, E, boolean>;
export declare function anyM<M extends URIS2, E>(M: Monad2C<M, E>): (xs: ReadonlyArray<Kind2<M, E, boolean>>) => Kind2<M, E, boolean>;
export declare function anyM<M extends URIS>(M: Monad1<M>): (xs: ReadonlyArray<Kind<M, boolean>>) => Kind<M, boolean>;
/**
* Like `separate`, but records via `These` which of the partitions are
* non-empty.
*
* @example
* import { separateNE } from 'fp-ts-std/ReadonlyArray'
* import * as E from 'fp-ts/Either'
* import * as T from 'fp-ts/These'
*
* assert.deepStrictEqual(
* separateNE([E.left(1), E.right('two')]),
* T.both([1], ['two']),
* )
*
* assert.deepStrictEqual(
* separateNE([E.right('one')]),
* T.right(['one']),
* )
*
* @category 3 Functions
* @since 0.16.0
*/
export declare const separateNE: <A, B>(xs: ReadonlyNonEmptyArray<Either<A, B>>) => These<ReadonlyNonEmptyArray<A>, ReadonlyNonEmptyArray<B>>;
//# sourceMappingURL=ReadonlyArray.d.ts.map