/** * @since 1.0.0 */ /** * This file is ported from * * Scala (https://www.scala-lang.org) * * Copyright EPFL and Lightbend, Inc. * * Licensed under Apache License 2.0 * (http://www.apache.org/licenses/LICENSE-2.0). */ import * as Either from "@fp-ts/core/Either"; import * as Option from "@fp-ts/core/Option"; import type { Predicate, Refinement } from "@fp-ts/core/Predicate"; import * as Chunk from "@fp-ts/data/Chunk"; import * as Equal from "@fp-ts/data/Equal"; /** * @since 1.0.0 * @category symbol */ export declare const ListTypeId: unique symbol; /** * @since 1.0.0 * @category symbol */ export type ListTypeId = typeof ListTypeId; /** * Represents an immutable linked list of elements of type `A`. * * A `List` is optimal for last-in-first-out (LIFO), stack-like access patterns. * If you need another access pattern, for example, random access or FIFO, * consider using a collection more suited for that other than `List`. * * @since 1.0.0 * @category models */ export type List = Cons | Nil; /** * @since 1.0.0 * @category models */ export interface Cons extends List.Variance, Iterable, Equal.Equal { readonly _tag: "Cons"; readonly head: A; readonly tail: List; } /** * @since 1.0.0 * @category models */ export interface Nil extends List.Variance, Iterable, Equal.Equal { readonly _tag: "Nil"; } type ConsNS = Cons; type NilNS = Nil; /** * @since 1.0.0 */ export declare namespace List { /** * @since 1.0.0 * @category models */ interface Variance { readonly [ListTypeId]: { readonly _A: (_: never) => A; }; } /** * @since 1.0.0 * @category models */ type Cons = ConsNS; /** * @since 1.0.0 * @category models */ type Nil = NilNS; } /** * Returns `true` if the specified value is a `List`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export declare const isList: { (u: Iterable): u is List; (u: unknown): u is List; }; /** * Returns `true` if the specified value is a `List.Nil`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export declare const isNil: (self: List) => self is Nil; /** * Returns `true` if the specified value is a `List.Cons`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export declare const isCons: (self: List) => self is Cons; /** * Returns the number of elements contained in the specified `List` * * @since 1.0.0 * @category getters */ export declare const length: (self: List) => number; /** * Returns `true` if the two lists are equal according to the provided function, * `false` otherwise. * * @since 1.0.0 * @category combinators */ export declare const equalsWith: ((self: List, that: List, f: (a: A, b: B) => boolean) => boolean) & ((that: List, f: (a: A_1, b: B_1) => boolean) => (self: List) => boolean); /** * Constructs a new `List.Nil`. * * @since 1.0.0 * @category constructors */ export declare const nil: () => List.Nil; /** * Constructs a new `List.Cons` from the specified `head` and `tail` values. * * @since 1.0.0 * @category constructors */ export declare const cons: (head: A, tail: List) => List.Cons; /** * Constructs a new empty `List`. * * @since 1.0.0 * @category constructors */ export declare const empty: () => List; /** * Constructs a new `List` from the specified value. * * @since 1.0.0 * @category constructors */ export declare const of: (value: A) => List; /** * Constructs a new `List` from the specified `Iterable`. * * @since 1.0.0 * @category constructors */ export declare const fromIterable: (prefix: Iterable) => List; /** * Constructs a new `List` from the specified values. * * @since 1.0.0 * @category constructors */ export declare const make: (...elements: Elements) => List; /** * Removes all `None` values from the specified list. * * @since 1.0.0 * @category combinators */ export declare const compact: (self: Iterable>) => List; /** * Concatentates the specified lists together. * * @since 1.0.0 * @category combinators */ export declare const concat: ((self: List, that: List) => List) & ((that: List) => (self: List) => List); /** * Drops the first `n` elements from the specified list. * * @since 1.0.0 * @category combinators */ export declare const drop: ((self: List, n: number) => List) & ((n: number) => (self: List) => List); /** * Returns `true` if all elements of the specified list satisfy the specified * predicate, `false` otherwise. * * @since 1.0.0 * @category combinators */ export declare const every: ((self: List, predicate: Predicate) => boolean) & ((predicate: Predicate) => (self: List) => boolean); /** * Filters a list using the specified predicate. * * @since 1.0.0 * @category combinators */ export declare const filter: { (self: List, refinement: Refinement): List; (self: List, predicate: Predicate): List; } & { (refinement: Refinement): (self: List) => List; (predicate: Predicate): (self: List) => List; }; /** * Filters and maps a list using the specified partial function. The resulting * list may be smaller than the input list due to the possibility of the partial * function not being defined for some elements. * * @since 1.0.0 * @category combinators */ export declare const filterMap: ((self: Iterable, pf: (a: A) => Option.Option) => List) & ((pf: (a: A_1) => Option.Option) => (self: Iterable) => List); /** * Returns the first element of the specified list that satisfies the specified * predicate, or `None` if no such element exists. * * @since 1.0.0 * @category combinators */ export declare const findFirst: { (self: List, refinement: Refinement): Option.Option; (self: List, predicate: Predicate): Option.Option; } & { (refinement: Refinement): (self: List) => Option.Option; (predicate: Predicate): (self: List) => Option.Option; }; /** * Flat maps a list using the specified function. * * @since 1.0.0 * @category combinators */ export declare const flatMap: ((self: List, f: (a: A) => List) => List) & ((f: (a: A_1) => List) => (self: List) => List); /** * Applies the specified function to each element of the list. * * @since 1.0.0 * @category combinators */ export declare const forEach: ((self: List, f: (a: A) => B) => void) & ((f: (a: A_1) => B_1) => (self: List) => void); /** * Returns the first element of the specified list, or `None` if the list is * empty. * * @since 1.0.0 * @category getters */ export declare const head: (self: List) => Option.Option; /** * Returns the last element of the specified list, or `None` if the list is * empty. * * @since 1.0.0 * @category getters */ export declare const last: (self: List) => Option.Option; /** * Applies the specified mapping function to each element of the list. * * @since 1.0.0 * @category combinators */ export declare const map: ((self: List, f: (a: A) => B) => List) & ((f: (a: A_1) => B_1) => (self: List) => List); /** * Partition a list into two lists, where the first list contains all elements * that did not satisfy the specified predicate, and the second list contains * all elements that did satisfy the specified predicate. * * @since 1.0.0 * @category combinators */ export declare const partition: ((self: List, predicate: Predicate) => readonly [List, List]) & ((predicate: Predicate) => (self: List) => readonly [List, List]); /** * Partition a list into two lists, where the first list contains all elements * for which the specified function returned a `Left`, and the second list * contains all elements for which the specified function returned a `Right`. * * @since 1.0.0 * @category combinators */ export declare const partitionMap: ((self: List, f: (a: A) => Either.Either) => readonly [List, List]) & ((f: (a: A_1) => Either.Either) => (self: List) => readonly [List, List]); /** * Prepends the specified element to the beginning of the list. * * @since 1.0.0 * @category combinators */ export declare const prepend: ((self: List, element: B) => Cons) & ((element: B_1) => (self: List) => Cons); /** * Prepends the specified prefix list to the beginning of the specified list. * * @since 1.0.0 * @category combinators */ export declare const prependAll: ((self: List, prefix: List) => List) & ((prefix: List) => (self: List) => List); /** * Prepends the specified prefix list (in reverse order) to the beginning of the * specified list. * * @since 1.0.0 * @category combinators */ export declare const prependAllReversed: ((self: List, prefix: List) => List) & ((prefix: List) => (self: List) => List); /** * Folds over the elements of the list using the specified function, using the * specified initial value. * * @since 1.0.0 * @category combinators */ export declare const reduce: ((self: List, zero: Z, f: (b: Z, a: A) => Z) => Z) & ((zero: Z_1, f: (b: Z_1, a: A_1) => Z_1) => (self: List) => Z_1); /** * Folds over the elements of the list using the specified function, beginning * with the last element of the list, using the specified initial value. * * @since 1.0.0 * @category combinators */ export declare const reduceRight: ((self: List, zero: Z, f: (accumulator: Z, value: A) => Z) => Z) & ((zero: Z_1, f: (accumulator: Z_1, value: A_1) => Z_1) => (self: List) => Z_1); /** * Returns a new list with the elements of the specified list in reverse order. * * @since 1.0.0 * @category combinators */ export declare const reverse: (self: List) => List; /** * Returns `true` if any element of the specified list satisfies the specified * predicate, `false` otherwise. * * @since 1.0.0 * @category combinators */ export declare const some: ((self: List, predicate: Predicate) => boolean) & ((predicate: Predicate) => (self: List) => boolean); /** * Splits the specified list into two lists at the specified index. * * @since 1.0.0 * @category combinators */ export declare const splitAt: ((self: List, n: number) => readonly [List, List]) & ((n: number) => (self: List) => readonly [List, List]); /** * Returns the tail of the specified list, or `None` if the list is empty. * * @since 1.0.0 * @category getters */ export declare const tail: (self: List) => Option.Option>; /** * Takes the specified number of elements from the beginning of the specified * list. * * @since 1.0.0 * @category combinators */ export declare const take: ((self: List, n: number) => List) & ((n: number) => (self: List) => List); /** * Converts the specified list to a `Chunk`. * * @since 1.0.0 * @category conversions */ export declare const toChunk: (self: List) => Chunk.Chunk; /** * Converts the specified list to a `ReadonlyArray`. * * @since 1.0.0 * @category conversions */ export declare const toReadonlyArray: (self: List) => readonly A[]; /** * Unsafely returns the first element of the specified `List`. * * @since 1.0.0 * @category unsafe */ export declare const unsafeHead: (self: List) => A; /** * Unsafely returns the last element of the specified `List`. * * @since 1.0.0 * @category unsafe */ export declare const unsafeLast: (self: List) => A; /** * Unsafely returns the tail of the specified `List`. * * @since 1.0.0 * @category unsafe */ export declare const unsafeTail: (self: List) => List; export {}; //# sourceMappingURL=List.d.ts.map