/** * Adapted from https://github.com/purescript/purescript-lists * * @since 0.1.8 */ import { Applicative1 } from 'fp-ts/lib/Applicative' import { Apply1 } from 'fp-ts/lib/Apply' import * as Eq from 'fp-ts/lib/Eq' import { Foldable1 } from 'fp-ts/lib/Foldable' import { Predicate, Refinement } from 'fp-ts/lib/function' import { Functor1 } from 'fp-ts/lib/Functor' import { Monad1 } from 'fp-ts/lib/Monad' import { Monoid } from 'fp-ts/lib/Monoid' import * as O from 'fp-ts/lib/Option' import { Semigroup } from 'fp-ts/lib/Semigroup' import { Show } from 'fp-ts/lib/Show' import { Traversable1 } from 'fp-ts/lib/Traversable' /** * @category model * @since 0.1.8 */ export interface Nil { readonly type: 'Nil' readonly length: 0 } /** * @category model * @since 0.1.8 */ export interface Cons { readonly type: 'Cons' readonly head: A readonly tail: List readonly length: number } /** * @category model * @since 0.1.8 */ export declare type List = Nil | Cons /** * @category constructors * @since 0.1.8 */ export declare const nil: List /** * Attaches an element to the front of a list. * * @example * import * as L from 'fp-ts-contrib/List' * * assert.deepStrictEqual(L.cons('a', L.nil), { type: 'Cons', head: 'a', tail: L.nil, length: 1 }) * * @category constructors * @since 0.1.8 */ export declare const cons: (head: A, tail: List) => List /** * Creates a list from an array * * @example * import * as L from 'fp-ts-contrib/List' * * assert.deepStrictEqual(L.fromArray([]), L.nil) * assert.deepStrictEqual(L.fromArray(['a', 'b']), L.cons('a', L.of('b'))) * * @category constructors * @since 0.1.8 */ export declare const fromArray: (as: A[]) => List /** * Gets the first element in a list, or `None` if the list is empty. * * @example * import * as O from 'fp-ts/Option' * import * as L from 'fp-ts-contrib/List' * * assert.deepStrictEqual(L.head(L.nil), O.none) * assert.deepStrictEqual(L.head(L.cons('x', L.of('a'))), O.some('x')) * * @category destructors * @since 0.1.8 */ export declare const head: (fa: List) => O.Option /** * Gets all but the first element of a list, or `None` if the list is empty. * * @example * import * as O from 'fp-ts/Option' * import * as L from 'fp-ts-contrib/List' * * assert.deepStrictEqual(L.tail(L.nil), O.none) * assert.deepStrictEqual(L.tail(L.of('a')), O.some(L.nil)) * assert.deepStrictEqual(L.tail(L.cons('x', L.of('a'))), O.some(L.of('a'))) * * @category destructors * @since 0.1.8 */ export declare const tail: (fa: List) => O.Option> /** * Breaks a list into its first element and the remaining elements. * * @example * import * as L from 'fp-ts-contrib/List' * * const len: (as: L.List) => number = L.foldLeft( * () => 0, * (_, tail) => 1 + len(tail) * ) * assert.deepStrictEqual(len(L.cons('a', L.of('b'))), 2) * * @category destructors * @since 0.1.8 */ export declare const foldLeft: (onNil: () => B, onCons: (head: A, tail: List) => B) => (fa: List) => B /** * Gets an array from a list. * * @example * import * as L from 'fp-ts-contrib/List' * * assert.deepStrictEqual(L.toArray(L.cons('a', L.of('b'))), ['a', 'b']) * * @category destructors * @since 0.1.8 */ export declare const toArray: (fa: List) => A[] /** * Gets an array from a list in a reversed order. * * @example * import * as L from 'fp-ts-contrib/List' * * assert.deepStrictEqual(L.toReversedArray(L.cons('a', L.of('b'))), ['b', 'a']) * * @category destructors * @since 0.1.8 */ export declare const toReversedArray: (fa: List) => A[] /** * Reverse a list. * * @example * import * as L from 'fp-ts-contrib/List' * * assert.deepStrictEqual(L.reverse(L.cons(1, L.cons(2, L.of(3)))), L.cons(3, L.cons(2, L.of(1)))) * * @category combinators * @since 0.1.8 */ export declare const reverse: (fa: List) => List /** * Drops the specified number of elements from the front of a list. * * @example * import * as L from 'fp-ts-contrib/List' * * assert.deepStrictEqual(L.dropLeft(1)(L.nil), L.nil) * assert.deepStrictEqual(L.dropLeft(1)(L.cons(1, L.of(2))), L.of(2)) * assert.deepStrictEqual(L.dropLeft(3)(L.cons(1, L.of(2))), L.nil) * * @category combinators * @since 0.1.8 */ export declare const dropLeft: (n: number) => (fa: List) => List /** * Drops those elements from the front of a list which match a predicate. * * @example * import * as L from 'fp-ts-contrib/List' * * const isLTThree = (n: number) => n < 3 * assert.deepStrictEqual(L.dropLeftWhile(isLTThree)(L.nil), L.nil) * assert.deepStrictEqual(L.dropLeftWhile(isLTThree)(L.cons(1, L.cons(2, L.of(3)))), L.of(3)) * assert.deepStrictEqual(L.dropLeftWhile(isLTThree)(L.cons(1, L.of(2))), L.nil) * * @since 0.1.8 */ export declare function dropLeftWhile(refinement: Refinement): (fa: List) => List export declare function dropLeftWhile(predicate: Predicate): (fa: List) => List /** * @category Functor * @since 0.1.18 */ export declare const map: (f: (a: A) => B) => (fa: List) => List /** * @category Functor * @since 0.1.20 */ export declare const ap: (fa: List) => (fab: List<(a: A) => B>) => List /** * @category Apply * @since 0.1.20 */ export declare const apFirst: (fb: List) => (fa: List) => List /** * @category Apply * @since 0.1.20 */ export declare const apSecond: (fb: List) => (fa: List) => List /** * @category Monad * @since 0.1.20 */ export declare const chain: (f: (a: A) => List) => (ma: List) => List /** * @category Monad * @since 0.1.20 */ export declare const chainFirst: (f: (a: A) => List) => (fa: List) => List /** * @category Foldable * @since 0.1.18 */ export declare const reduce: (b: B, f: (b: B, a: A) => B) => (fa: List) => B /** * @category Foldable * @since 0.1.18 */ export declare const reduceRight: (b: B, f: (a: A, b: B) => B) => (fa: List) => B /** * @category Foldable * @since 0.1.18 */ export declare const foldMap: (M: Monoid) => (f: (a: A) => M) => (fa: List) => M /** * @category Traversable * @since 0.1.18 */ export declare const sequence: Traversable1['sequence'] /** * Creates a list with a single element. * * @example * import * as L from 'fp-ts-contrib/List' * * assert.deepStrictEqual(L.of('a'), L.cons('a', L.nil)) * * @category Applicative * @since 0.1.8 */ export declare const of: (head: A) => List /** * Finds the first index for which a predicate holds. * * @example * import * as O from 'fp-ts/Option' * import * as L from 'fp-ts-contrib/List' * * const f = (a: number): boolean => a % 2 === 0 * const findIndexEven = L.findIndex(f) * assert.deepStrictEqual(findIndexEven(L.nil), O.none) * assert.deepStrictEqual(findIndexEven(L.cons(1, L.of(2))), O.some(1)) * assert.deepStrictEqual(findIndexEven(L.of(1)), O.none) * * @since 0.1.8 */ export declare const findIndex: (predicate: Predicate) => (fa: List) => O.Option /** * @category instances * @since 0.1.8 */ export declare const URI = 'List' /** * @category instances * @since 0.1.8 */ export declare type URI = typeof URI declare module 'fp-ts/lib/HKT' { interface URItoKind { List: List } } /** * Derives an `Eq` over the `List` of a given element type from the `Eq` of that type. * The derived `Eq` defines two lists as equal if all elements of both lists * are compared equal pairwise with the given `E`. In case of lists of different * lengths, the result is non equality. * * @example * import { eqString } from 'fp-ts/Eq' * import * as L from 'fp-ts-contrib/List' * * const E = L.getEq(eqString) * assert.strictEqual(E.equals(L.cons('a', L.of('b')), L.cons('a', L.of('b'))), true) * assert.strictEqual(E.equals(L.of('x'), L.nil), false) * * @category instances * @since 0.1.8 */ export declare const getEq: (E: Eq.Eq) => Eq.Eq> /** * @category instances * @since 0.1.20 */ export declare const getShow: (S: Show) => Show> /** * @category instances * @since 0.1.20 */ export declare const getSemigroup: () => Semigroup> /** * @category instances * @since 0.1.20 */ export declare const getMonoid: () => Monoid> /** * @category instances * @since 0.1.18 */ export declare const Functor: Functor1 /** * @category instances * @since 0.1.20 */ export declare const Apply: Apply1 /** * @category instances * @since 0.1.20 */ export declare const Applicative: Applicative1 /** * @category instances * @since 0.1.20 */ export declare const Monad: Monad1 /** * @category instances * @since 0.1.18 */ export declare const Foldable: Foldable1 /** * @category instances * @since 0.1.18 */ export declare const Traversable: Traversable1 /** * @category instances * @since 0.1.8 */ export declare const list: Functor1 & Foldable1 & Traversable1 /** * @since 0.1.20 */ export declare const bindTo: (name: N) => (fa: List) => List<{ [K in N]: A }> /** * @since 0.1.20 */ export declare const bind: ( name: Exclude, f: (a: A) => List ) => (fa: List) => List<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }> /** * @since 0.1.20 */ export declare const apS: ( name: Exclude, fb: List ) => (fa: List) => List<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }> /** * Tests whether a list is an empty list. * * @example * import * as L from 'fp-ts-contrib/List' * * assert.strictEqual(L.isNil(L.nil), true) * assert.strictEqual(L.isNil(L.of(6)), false) * * @since 0.1.8 */ export declare const isNil: (a: List) => a is Nil /** * Tests whether a list is a non empty list. * * @example * import * as L from 'fp-ts-contrib/List' * * assert.strictEqual(L.isCons(L.nil), false) * assert.strictEqual(L.isCons(L.of(1)), true) * * @since 0.1.8 */ export declare const isCons: (a: List) => a is Cons