/** * A data type for immutable linked lists representing ordered collections of elements of type `A`. * * This data type 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 to this than `List`. * * **Performance** * * - Time: `List` has `O(1)` prepend and head/tail access. Most other operations are `O(n)` on the number of elements in the list. This includes the index-based lookup of elements, `length`, `append` and `reverse`. * - Space: `List` implements structural sharing of the tail list. This means that many operations are either zero- or constant-memory cost. * * @since 2.0.0 */ import * as Chunk from "./Chunk.js"; import * as Either from "./Either.js"; import * as Equal from "./Equal.js"; import * as Equivalence from "./Equivalence.js"; import { type Inspectable } from "./Inspectable.js"; import type { NonEmptyIterable } from "./NonEmptyIterable.js"; import * as Option from "./Option.js"; import type { Pipeable } from "./Pipeable.js"; import { type Predicate, type Refinement } from "./Predicate.js"; import type { NoInfer } from "./Types.js"; /** * 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 2.0.0 * @category models */ export type List = Cons | Nil; /** * @since 2.0.0 * @category symbol */ export declare const TypeId: unique symbol; /** * @since 2.0.0 * @category symbol */ export type TypeId = typeof TypeId; /** * @since 2.0.0 * @category models */ export interface Nil extends Iterable, Equal.Equal, Pipeable, Inspectable { readonly [TypeId]: TypeId; readonly _tag: "Nil"; } /** * @since 2.0.0 * @category models */ export interface Cons extends NonEmptyIterable, Equal.Equal, Pipeable, Inspectable { readonly [TypeId]: TypeId; readonly _tag: "Cons"; readonly head: A; readonly tail: List; } /** * Converts the specified `List` to an `Array`. * * @category conversions * @since 2.0.0 */ export declare const toArray: (self: List) => Array; /** * @category equivalence * @since 2.0.0 */ export declare const getEquivalence: (isEquivalent: Equivalence.Equivalence) => Equivalence.Equivalence>; /** * Returns `true` if the specified value is a `List`, `false` otherwise. * * @since 2.0.0 * @category refinements */ export declare const isList: { /** * Returns `true` if the specified value is a `List`, `false` otherwise. * * @since 2.0.0 * @category refinements */ (u: Iterable): u is List; /** * Returns `true` if the specified value is a `List`, `false` otherwise. * * @since 2.0.0 * @category refinements */ (u: unknown): u is List; }; /** * Returns `true` if the specified value is a `List.Nil`, `false` otherwise. * * @since 2.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 2.0.0 * @category refinements */ export declare const isCons: (self: List) => self is Cons; /** * Returns the number of elements contained in the specified `List` * * @since 2.0.0 * @category getters */ export declare const size: (self: List) => number; /** * Constructs a new empty `List`. * * @since 2.0.0 * @category constructors */ export declare const nil: () => List; /** * Constructs a new `List.Cons` from the specified `head` and `tail` values. * * @since 2.0.0 * @category constructors */ export declare const cons: (head: A, tail: List) => Cons; /** * Constructs a new empty `List`. * * Alias of {@link nil}. * * @since 2.0.0 * @category constructors */ export declare const empty: () => List; /** * Constructs a new `List` from the specified value. * * @since 2.0.0 * @category constructors */ export declare const of: (value: A) => Cons; /** * Creates a new `List` from an iterable collection of values. * * @since 2.0.0 * @category constructors */ export declare const fromIterable: (prefix: Iterable) => List; /** * Constructs a new `List` from the specified values. * * @since 2.0.0 * @category constructors */ export declare const make: ]>(...elements: Elements) => Cons; /** * Appends the specified element to the end of the `List`, creating a new `Cons`. * * @category concatenating * @since 2.0.0 */ export declare const append: { /** * Appends the specified element to the end of the `List`, creating a new `Cons`. * * @category concatenating * @since 2.0.0 */ (element: B): (self: List) => Cons; /** * Appends the specified element to the end of the `List`, creating a new `Cons`. * * @category concatenating * @since 2.0.0 */ (self: List, element: B): Cons; }; /** * Concatenates two lists, combining their elements. * If either list is non-empty, the result is also a non-empty list. * * @example * ```ts * import * as assert from "node:assert" * import { List } from "effect" * * assert.deepStrictEqual( * List.make(1, 2).pipe(List.appendAll(List.make("a", "b")), List.toArray), * [1, 2, "a", "b"] * ) * ``` * * @category concatenating * @since 2.0.0 */ export declare const appendAll: { /** * Concatenates two lists, combining their elements. * If either list is non-empty, the result is also a non-empty list. * * @example * ```ts * import * as assert from "node:assert" * import { List } from "effect" * * assert.deepStrictEqual( * List.make(1, 2).pipe(List.appendAll(List.make("a", "b")), List.toArray), * [1, 2, "a", "b"] * ) * ``` * * @category concatenating * @since 2.0.0 */ , T extends List>(that: T): (self: S) => List.OrNonEmpty | List.Infer>; /** * Concatenates two lists, combining their elements. * If either list is non-empty, the result is also a non-empty list. * * @example * ```ts * import * as assert from "node:assert" * import { List } from "effect" * * assert.deepStrictEqual( * List.make(1, 2).pipe(List.appendAll(List.make("a", "b")), List.toArray), * [1, 2, "a", "b"] * ) * ``` * * @category concatenating * @since 2.0.0 */ (self: List, that: Cons): Cons; /** * Concatenates two lists, combining their elements. * If either list is non-empty, the result is also a non-empty list. * * @example * ```ts * import * as assert from "node:assert" * import { List } from "effect" * * assert.deepStrictEqual( * List.make(1, 2).pipe(List.appendAll(List.make("a", "b")), List.toArray), * [1, 2, "a", "b"] * ) * ``` * * @category concatenating * @since 2.0.0 */ (self: Cons, that: List): Cons; /** * Concatenates two lists, combining their elements. * If either list is non-empty, the result is also a non-empty list. * * @example * ```ts * import * as assert from "node:assert" * import { List } from "effect" * * assert.deepStrictEqual( * List.make(1, 2).pipe(List.appendAll(List.make("a", "b")), List.toArray), * [1, 2, "a", "b"] * ) * ``` * * @category concatenating * @since 2.0.0 */ (self: List, that: List): List; }; /** * Prepends the specified element to the beginning of the list. * * @category concatenating * @since 2.0.0 */ export declare const prepend: { /** * Prepends the specified element to the beginning of the list. * * @category concatenating * @since 2.0.0 */ (element: B): (self: List) => Cons; /** * Prepends the specified element to the beginning of the list. * * @category concatenating * @since 2.0.0 */ (self: List, element: B): Cons; }; /** * Prepends the specified prefix list to the beginning of the specified list. * If either list is non-empty, the result is also a non-empty list. * * @example * ```ts * import * as assert from "node:assert" * import { List } from "effect" * * assert.deepStrictEqual( * List.make(1, 2).pipe(List.prependAll(List.make("a", "b")), List.toArray), * ["a", "b", 1, 2] * ) * ``` * * @category concatenating * @since 2.0.0 */ export declare const prependAll: { /** * Prepends the specified prefix list to the beginning of the specified list. * If either list is non-empty, the result is also a non-empty list. * * @example * ```ts * import * as assert from "node:assert" * import { List } from "effect" * * assert.deepStrictEqual( * List.make(1, 2).pipe(List.prependAll(List.make("a", "b")), List.toArray), * ["a", "b", 1, 2] * ) * ``` * * @category concatenating * @since 2.0.0 */ , T extends List>(that: T): (self: S) => List.OrNonEmpty | List.Infer>; /** * Prepends the specified prefix list to the beginning of the specified list. * If either list is non-empty, the result is also a non-empty list. * * @example * ```ts * import * as assert from "node:assert" * import { List } from "effect" * * assert.deepStrictEqual( * List.make(1, 2).pipe(List.prependAll(List.make("a", "b")), List.toArray), * ["a", "b", 1, 2] * ) * ``` * * @category concatenating * @since 2.0.0 */ (self: List, that: Cons): Cons; /** * Prepends the specified prefix list to the beginning of the specified list. * If either list is non-empty, the result is also a non-empty list. * * @example * ```ts * import * as assert from "node:assert" * import { List } from "effect" * * assert.deepStrictEqual( * List.make(1, 2).pipe(List.prependAll(List.make("a", "b")), List.toArray), * ["a", "b", 1, 2] * ) * ``` * * @category concatenating * @since 2.0.0 */ (self: Cons, that: List): Cons; /** * Prepends the specified prefix list to the beginning of the specified list. * If either list is non-empty, the result is also a non-empty list. * * @example * ```ts * import * as assert from "node:assert" * import { List } from "effect" * * assert.deepStrictEqual( * List.make(1, 2).pipe(List.prependAll(List.make("a", "b")), List.toArray), * ["a", "b", 1, 2] * ) * ``` * * @category concatenating * @since 2.0.0 */ (self: List, that: List): List; }; /** * Prepends the specified prefix list (in reverse order) to the beginning of the * specified list. * * @category concatenating * @since 2.0.0 */ export declare const prependAllReversed: { /** * Prepends the specified prefix list (in reverse order) to the beginning of the * specified list. * * @category concatenating * @since 2.0.0 */ (prefix: List): (self: List) => List; /** * Prepends the specified prefix list (in reverse order) to the beginning of the * specified list. * * @category concatenating * @since 2.0.0 */ (self: List, prefix: List): List; }; /** * Drops the first `n` elements from the specified list. * * @since 2.0.0 * @category combinators */ export declare const drop: { /** * Drops the first `n` elements from the specified list. * * @since 2.0.0 * @category combinators */ (n: number): (self: List) => List; /** * Drops the first `n` elements from the specified list. * * @since 2.0.0 * @category combinators */ (self: List, n: number): List; }; /** * Check if a predicate holds true for every `List` element. * * @since 2.0.0 * @category elements */ export declare const every: { /** * Check if a predicate holds true for every `List` element. * * @since 2.0.0 * @category elements */ (refinement: Refinement, B>): (self: List) => self is List; /** * Check if a predicate holds true for every `List` element. * * @since 2.0.0 * @category elements */ (predicate: Predicate): (self: List) => boolean; /** * Check if a predicate holds true for every `List` element. * * @since 2.0.0 * @category elements */ (self: List, refinement: Refinement): self is List; /** * Check if a predicate holds true for every `List` element. * * @since 2.0.0 * @category elements */ (self: List, predicate: Predicate): boolean; }; /** * Check if a predicate holds true for some `List` element. * * @since 2.0.0 * @category elements */ export declare const some: { /** * Check if a predicate holds true for some `List` element. * * @since 2.0.0 * @category elements */ (predicate: Predicate>): (self: List) => self is Cons; /** * Check if a predicate holds true for some `List` element. * * @since 2.0.0 * @category elements */ (self: List, predicate: Predicate): self is Cons; }; /** * Filters a list using the specified predicate. * * @since 2.0.0 * @category combinators */ export declare const filter: { /** * Filters a list using the specified predicate. * * @since 2.0.0 * @category combinators */ (refinement: Refinement, B>): (self: List) => List; /** * Filters a list using the specified predicate. * * @since 2.0.0 * @category combinators */ (predicate: Predicate>): (self: List) => List; /** * Filters a list using the specified predicate. * * @since 2.0.0 * @category combinators */ (self: List, refinement: Refinement): List; /** * Filters a list using the specified predicate. * * @since 2.0.0 * @category combinators */ (self: List, predicate: Predicate): 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 2.0.0 * @category combinators */ export declare const filterMap: { /** * 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 2.0.0 * @category combinators */ (f: (a: A) => Option.Option): (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 2.0.0 * @category combinators */ (self: List, f: (a: A) => Option.Option): List; }; /** * Removes all `None` values from the specified list. * * @since 2.0.0 * @category combinators */ export declare const compact: (self: List>) => List; /** * Returns the first element that satisfies the specified * predicate, or `None` if no such element exists. * * @category elements * @since 2.0.0 */ export declare const findFirst: { /** * Returns the first element that satisfies the specified * predicate, or `None` if no such element exists. * * @category elements * @since 2.0.0 */ (refinement: Refinement, B>): (self: List) => Option.Option; /** * Returns the first element that satisfies the specified * predicate, or `None` if no such element exists. * * @category elements * @since 2.0.0 */ (predicate: Predicate>): (self: List) => Option.Option; /** * Returns the first element that satisfies the specified * predicate, or `None` if no such element exists. * * @category elements * @since 2.0.0 */ (self: List, refinement: Refinement): Option.Option; /** * Returns the first element that satisfies the specified * predicate, or `None` if no such element exists. * * @category elements * @since 2.0.0 */ (self: List, predicate: Predicate): Option.Option; }; /** * Applies a function to each element in a list and returns a new list containing the concatenated mapped elements. * * @since 2.0.0 * @category sequencing */ export declare const flatMap: { /** * Applies a function to each element in a list and returns a new list containing the concatenated mapped elements. * * @since 2.0.0 * @category sequencing */ , T extends List>(f: (a: List.Infer, i: number) => T): (self: S) => List.AndNonEmpty>; /** * Applies a function to each element in a list and returns a new list containing the concatenated mapped elements. * * @since 2.0.0 * @category sequencing */ (self: Cons, f: (a: A, i: number) => Cons): Cons; /** * Applies a function to each element in a list and returns a new list containing the concatenated mapped elements. * * @since 2.0.0 * @category sequencing */ (self: List, f: (a: A, i: number) => List): List; }; /** * Applies the specified function to each element of the `List`. * * @since 2.0.0 * @category combinators */ export declare const forEach: { /** * Applies the specified function to each element of the `List`. * * @since 2.0.0 * @category combinators */ (f: (a: A) => B): (self: List) => void; /** * Applies the specified function to each element of the `List`. * * @since 2.0.0 * @category combinators */ (self: List, f: (a: A) => B): void; }; /** * Returns the first element of the specified list, or `None` if the list is * empty. * * @since 2.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 2.0.0 * @category getters */ export declare const last: (self: List) => Option.Option; /** * @since 2.0.0 */ export declare namespace List { /** * @since 2.0.0 */ type Infer> = S extends List ? A : never; /** * @since 2.0.0 */ type With, A> = S extends Cons ? Cons : List; /** * @since 2.0.0 */ type OrNonEmpty, T extends List, A> = S extends Cons ? Cons : T extends Cons ? Cons : List; /** * @since 2.0.0 */ type AndNonEmpty, T extends List, A> = S extends Cons ? T extends Cons ? Cons : List : List; } /** * Applies the specified mapping function to each element of the list. * * @since 2.0.0 * @category mapping */ export declare const map: { /** * Applies the specified mapping function to each element of the list. * * @since 2.0.0 * @category mapping */ , B>(f: (a: List.Infer, i: number) => B): (self: S) => List.With; /** * Applies the specified mapping function to each element of the list. * * @since 2.0.0 * @category mapping */ , B>(self: S, f: (a: List.Infer, i: number) => B): List.With; }; /** * 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 2.0.0 * @category combinators */ export declare const partition: { /** * 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 2.0.0 * @category combinators */ (refinement: Refinement, B>): (self: List) => [excluded: List>, satisfying: 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 2.0.0 * @category combinators */ (predicate: Predicate>): (self: List) => [excluded: List, satisfying: 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 2.0.0 * @category combinators */ (self: List, refinement: Refinement): [excluded: List>, satisfying: 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 2.0.0 * @category combinators */ (self: List, predicate: Predicate): [excluded: List, satisfying: 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 2.0.0 * @category combinators */ export declare const partitionMap: { /** * 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 2.0.0 * @category combinators */ (f: (a: A) => Either.Either): (self: List) => [left: List, right: 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 2.0.0 * @category combinators */ (self: List, f: (a: A) => Either.Either): [left: List, right: List]; }; /** * Folds over the elements of the list using the specified function, using the * specified initial value. * * @since 2.0.0 * @category folding */ export declare const reduce: { /** * Folds over the elements of the list using the specified function, using the * specified initial value. * * @since 2.0.0 * @category folding */ (zero: Z, f: (b: Z, a: A) => Z): (self: List) => Z; /** * Folds over the elements of the list using the specified function, using the * specified initial value. * * @since 2.0.0 * @category folding */ (self: List, zero: Z, f: (b: Z, a: A) => Z): Z; }; /** * 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 2.0.0 * @category folding */ export declare const reduceRight: { /** * 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 2.0.0 * @category folding */ (zero: Z, f: (accumulator: Z, value: A) => Z): (self: List) => Z; /** * 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 2.0.0 * @category folding */ (self: List, zero: Z, f: (accumulator: Z, value: A) => Z): Z; }; /** * Returns a new list with the elements of the specified list in reverse order. * * @since 2.0.0 * @category elements */ export declare const reverse: (self: List) => List; /** * Splits the specified list into two lists at the specified index. * * @since 2.0.0 * @category combinators */ export declare const splitAt: { /** * Splits the specified list into two lists at the specified index. * * @since 2.0.0 * @category combinators */ (n: number): (self: List) => [beforeIndex: List, fromIndex: List]; /** * Splits the specified list into two lists at the specified index. * * @since 2.0.0 * @category combinators */ (self: List, n: number): [beforeIndex: List, fromIndex: List]; }; /** * Returns the tail of the specified list, or `None` if the list is empty. * * @since 2.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 2.0.0 * @category combinators */ export declare const take: { /** * Takes the specified number of elements from the beginning of the specified * list. * * @since 2.0.0 * @category combinators */ (n: number): (self: List) => List; /** * Takes the specified number of elements from the beginning of the specified * list. * * @since 2.0.0 * @category combinators */ (self: List, n: number): List; }; /** * Converts the specified `List` to a `Chunk`. * * @since 2.0.0 * @category conversions */ export declare const toChunk: (self: List) => Chunk.Chunk; /** * Unsafely returns the first element of the specified `List`. * * @since 2.0.0 * @category unsafe */ export declare const unsafeHead: (self: List) => A; /** * Unsafely returns the last element of the specified `List`. * * @since 2.0.0 * @category unsafe */ export declare const unsafeLast: (self: List) => A; /** * Unsafely returns the tail of the specified `List`. * * @since 2.0.0 * @category unsafe */ export declare const unsafeTail: (self: List) => List; //# sourceMappingURL=List.d.ts.map