/** * 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 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 Chunk from "@effect/data/Chunk"; import * as Either from "@effect/data/Either"; import * as Equal from "@effect/data/Equal"; import * as Equivalence from "@effect/data/Equivalence"; import { type Inspectable } from "@effect/data/Inspectable"; import * as Option from "@effect/data/Option"; import type { Pipeable } from "@effect/data/Pipeable"; import type { Predicate, Refinement } from "@effect/data/Predicate"; import * as ReadonlyArray from "@effect/data/ReadonlyArray"; /** * 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 symbol */ export declare const TypeId: unique symbol; /** * @since 1.0.0 * @category symbol */ export type TypeId = typeof TypeId; /** * @since 1.0.0 * @category models */ export interface Nil extends Iterable, Equal.Equal, Pipeable, Inspectable { readonly [TypeId]: TypeId; readonly _tag: "Nil"; } /** * @since 1.0.0 * @category models */ export interface Cons extends Iterable, Equal.Equal, Pipeable, Inspectable { readonly [TypeId]: TypeId; readonly _tag: "Cons"; readonly head: A; readonly tail: List; } /** * Converts the specified `List` to a `ReadonlyArray`. * * @category conversions * @since 1.0.0 */ export declare const toReadonlyArray: (self: List) => readonly A[]; /** * @category equivalence * @since 1.0.0 */ export declare const getEquivalence: (isEquivalent: Equivalence.Equivalence) => Equivalence.Equivalence>; /** * 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 size: (self: List) => number; /** * Constructs a new empty `List`. * * @since 1.0.0 * @category constructors */ export declare const nil: () => List; /** * 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) => Cons; /** * Constructs a new empty `List`. * * Alias of {@link nil}. * * @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) => Cons; /** * 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) => Cons; /** * Appends the specified element to the end of the `List`, creating a new `Cons`. * * @category concatenating * @since 1.0.0 */ export declare const append: { (element: B): (self: List) => Cons; (self: List, element: B): Cons; }; /** * Concatentates the specified lists together. * * @category concatenating * @since 1.0.0 */ export declare const appendAll: { (that: List): (self: List) => List; (self: List, that: List): List; }; /** * @category concatenating * @since 1.0.0 */ export declare const appendAllNonEmpty: { (that: Cons): (self: List) => Cons; (that: List): (self: Cons) => Cons; (self: List, that: Cons): Cons; (self: Cons, that: List): Cons; }; /** * Prepends the specified element to the beginning of the list. * * @category concatenating * @since 1.0.0 */ export declare const prepend: { (element: B): (self: List) => Cons; (self: List, element: B): Cons; }; /** * Prepends the specified prefix list to the beginning of the specified list. * * @category concatenating * @since 1.0.0 */ export declare const prependAll: { (prefix: List): (self: List) => List; (self: List, prefix: List): List; }; /** * @category concatenating * @since 1.0.0 */ export declare const prependAllNonEmpty: { (that: Cons): (self: List) => Cons; (that: List): (self: Cons) => Cons; (self: List, that: Cons): Cons; (self: Cons, that: List): Cons; }; /** * Prepends the specified prefix list (in reverse order) to the beginning of the * specified list. * * @category concatenating * @since 1.0.0 */ export declare const prependAllReversed: { (prefix: List): (self: List) => List; (self: List, prefix: List): List; }; /** * Drops the first `n` elements from the specified list. * * @since 1.0.0 * @category combinators */ export declare const drop: { (n: number): (self: List) => List; (self: List, n: number): List; }; /** * Check if a predicate holds true for every `List` element. * * @since 1.0.0 * @category elements */ export declare const every: { (refinement: Refinement): (self: List) => self is List; (predicate: Predicate): (self: List) => boolean; (self: List, refinement: Refinement): self is List; (self: List, predicate: Predicate): boolean; }; /** * Check if a predicate holds true for some `List` element. * * @since 1.0.0 * @category elements */ export declare const some: { (predicate: Predicate): (self: List) => self is Cons; (self: List, predicate: Predicate): self is Cons; }; /** * Filters a list using the specified predicate. * * @since 1.0.0 * @category combinators */ export declare const filter: { (refinement: Refinement): (self: List) => List; (predicate: Predicate): (self: List) => List; (self: List, refinement: Refinement): List; (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 1.0.0 * @category combinators */ export declare const filterMap: { (f: (a: A) => Option.Option): (self: List) => List; (self: List, f: (a: A) => Option.Option): List; }; /** * Removes all `None` values from the specified list. * * @since 1.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 1.0.0 */ export declare const findFirst: { (refinement: Refinement): (self: List) => Option.Option; (predicate: Predicate): (self: List) => Option.Option; (self: List, refinement: Refinement): Option.Option; (self: List, predicate: Predicate): Option.Option; }; /** * Flat maps a list using the specified function. * * @since 1.0.0 * @category sequencing */ export declare const flatMap: { (f: (a: A) => List): (self: List) => List; (self: List, f: (a: A) => List): List; }; /** * @category sequencing * @since 1.0.0 */ export declare const flatMapNonEmpty: { (f: (a: A, i: number) => Cons): (self: Cons) => Cons; (self: Cons, f: (a: A, i: number) => Cons): Cons; }; /** * Applies the specified function to each element of the `List`. * * @since 1.0.0 * @category combinators */ export declare const forEach: { (f: (a: A) => B): (self: List) => void; (self: List, f: (a: A) => B): 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: { (f: (a: A) => B): (self: List) => List; (self: List, f: (a: A) => B): 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: { (refinement: Refinement): (self: List) => [List>, List]; (predicate: (a: A) => boolean): (self: List) => [List, List]; (self: List, refinement: Refinement): [List>, List]; (self: List, predicate: (a: A) => boolean): [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: { (f: (a: A) => Either.Either): (self: List) => readonly [List, List]; (self: List, f: (a: A) => Either.Either): readonly [List, List]; }; /** * Folds over the elements of the list using the specified function, using the * specified initial value. * * @since 1.0.0 * @category folding */ export declare const reduce: { (zero: Z, f: (b: Z, a: A) => Z): (self: List) => Z; (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 1.0.0 * @category folding */ export declare const reduceRight: { (zero: Z, f: (accumulator: Z, value: A) => Z): (self: List) => Z; (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 1.0.0 * @category elements */ export declare const reverse: (self: List) => List; /** * Splits the specified list into two lists at the specified index. * * @since 1.0.0 * @category combinators */ export declare const splitAt: { (n: number): (self: List) => readonly [List, List]; (self: List, n: number): 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: { (n: number): (self: List) => List; (self: List, n: number): List; }; /** * Converts the specified `List` to a `Chunk`. * * @since 1.0.0 * @category conversions */ export declare const toChunk: (self: List) => Chunk.Chunk; /** * 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; //# sourceMappingURL=List.d.ts.map