import type AppendFn from "./Append"; import type AtFn from "./At"; import type ConcatFn from "./Concat"; import type ConcatWFn from "./ConcatW"; import type ContainsFn from "./Contains"; import type CreateFn from "./Create"; import type EveryFn from "./Every"; import type ExtendFn from "./Extend"; import type ExtendLeftFn from "./ExtendLeft"; import type ExtendLeftWFn from "./ExtendLeftW"; import type ExtendWFn from "./ExtendW"; import type FilterFn from "./Filter"; import type FlatMapFn from "./FlatMap"; import type FlattenFn from "./Flatten"; import type FoldLFn from "./FoldL"; import type FoldRFn from "./FoldR"; import type HeadFn from "./Head"; import type InitFn from "./Init"; import type IsListFn from "./IsList"; import type { JoinFn } from "./Join"; import type LastFn from "./Last"; import type MapFn from "./Map"; import type PrependFn from "./Prepend"; import type RangeOfFn from "./RangeOf"; import type RejectFn from "./Reject"; import type ReverseFn from "./Reverse"; import type SumFn from "./Sum"; import type TailFn from "./Tail"; import type ToUnionFn from "./ToUnion"; import type { Fn1, Fn2, Param0, PartialApply } from "../HKT"; import type { Nat } from "../Num"; // @ts-ignore - Only used in doc comments import type { Tuple$$Of1 } from "../Tuple"; import type { Lazied, Lazied$Get } from "../helpers"; import type { Show } from "../typeclass/Show"; /** * Alias for `readonly T[]` to represent a tuple type. */ export type List = readonly T[]; /** * Lazied version of {@link List}. */ export interface ListL extends List> {} /** * Alias for `readonly [T, U]`. */ export type Pair = readonly [T, U]; /*********** * Methods * ***********/ /** * Methods for tuples. */ export namespace List { /** * [Fn] Apply a function to each element of a {@link List} (i.e., fixed-length tuple). * * Sig: `[f: (x: T) => U](xs: List) => List` */ export type Map = PartialApply; /** * [Fn] Filter a {@link List} (i.e., fixed-length tuple) based on a predicate. * * Sig: `(pred: (x: T) => boolean) => (xs: List) => List` * * @see {@link Reject} for the opposite. */ export type Filter> = PartialApply; /** * [Fn] Keep elements of a {@link List} (i.e., fixed-length tuple) that do not * satisfy a predicate. * * Sig: `[pred: (x: T) => boolean](xs: List) => List` * * @see {@link Filter} for the opposite. */ export type Reject> = PartialApply; /** * [Fn] Determine if every element in a {@link List} (i.e., fixed-length tuple) * satisfies a predicate. * * Sig: `[pred: (x: T) => boolean](xs: List) => boolean` */ export type Every> = PartialApply; /** * [Fn] Apply a function to each element of a {@link List} (i.e., fixed-length tuple) * and concatenate the results. * * Sig: `[f: (x: T) => List](xs: List) => List` */ export type FlatMap> = PartialApply; /** * [Fn] Flatten a {@link List} of {@link List}s into a single {@link List}. * * Sig: `(xs: List>) => List` */ export type Flatten = FlattenFn; /** * [Fn] Apply a binary function to each element of a {@link List} (i.e., fixed-length * tuple), starting from the **left**. The result of the previous application is passed as the * first argument to the next application. * * The **L** suffix stands for “**L**eft”. * * Sig: `[f: (acc: U, x: T) => U, init: U](xs: List) => U` */ export type FoldL> = PartialApply; /** * [Fn] Apply a binary function to each element of a {@link List} (i.e., fixed-length * tuple), starting from the **right**. The result of the previous application is passed as the * first argument to the next application. * * The **R** suffix stands for “**R**ight”. * * Sig: `[f: (acc: U, x: T) => U, init: U](xs: List) => U` */ export type FoldR> = PartialApply; /** * [Fn] Calculate the sum of a {@link List} of {@link Int}s. * * Sig: `(ns: List) => Int` */ export type Sum = SumFn; /** * [Fn] Check if a {@link List} contains a specific element. * * Sig: `[x: T](xs: List) => boolean` */ export type Contains = PartialApply; /** * [Fn] Reverse a {@link List}. * * Sig: `(xs: List) => List` */ export type Reverse = ReverseFn; /** * [Fn] Get the element at a specific index in a {@link List}. * * Sig: `[i: Nat](xs: List) => Option` */ export type At = PartialApply; /** * [Fn] Get the first element in a {@link List}. * * Sig: `(xs: List) => Option` */ export type Head = HeadFn; /** * [Fn] Get all elements in a {@link List} except the first one. * * Sig: `(xs: List) => Option>` */ export type Tail = TailFn; /** * [Fn] Get all elements in a {@link List} except the last one. * * Sig: `(xs: List) => Option>` */ export type Init = InitFn; /** * [Fn] Get the last element in a {@link List}. * * Sig: `(xs: List) => Option` */ export type Last = LastFn; /** * [Fn] Concatenate two {@link List}s. * * Sig: `(xs: List, ys: List) => List` */ export type Concat = ConcatFn; /** * [Fn] Less strict version of {@link Concat}. The **W** suffix (short for * **W**idening) means that both {@link List}s can hold different types. * * Sig: `(xs: List, ys: List) => List` */ export type ConcatW = ConcatWFn; /** * [Fn] Extend a {@link List} by concatenating another {@link List} on the **right**. * * Sig: `[ys: List](xs: List) => List` * * @see {@link ExtendLeft} for the opposite. */ export type Extend = PartialApply; /** * [Fn] Less strict version of {@link Extend}.The **W** suffix (short for **W**idening) means that * both {@link List}s can hold different types. * * Sig: `[ys: List](xs: List) => List` * * @see {@link ExtendLeftW} for the opposite. */ export type ExtendW = PartialApply; /** * [Fn] Extend a {@link List} by concatenating another {@link List} on the **left**. * * Sig: `[ys: List](xs: List) => List` * * @see {@link Extend} for the opposite. */ export type ExtendLeft = PartialApply; /** * [Fn] Less strict version of {@link ExtendLeft}.The **W** suffix (short for **W**idening) means * that both {@link List}s can hold different types. * * It is actually an alias of {@link ConcatW}. * * Sig: `[ys: List](xs: List) => List` * * @see {@link ExtendW} for the opposite. */ export type ExtendLeftW = PartialApply; /** * [Fn] Append an element to a {@link List} (i.e., fixed-length tuple). * * Sig: `[x: T](xs: List) => List` */ export type Append = PartialApply; /** * [Fn] Prepend an element to a {@link List} (i.e., fixed-length tuple). * * Sig: `[x: T](xs: List) => List` */ export type Prepend = PartialApply; /** * [Fn] Join a {@link List} of {@link Show}s into a single string. * * Sig: `[sep: Show](xs: List) => string` */ export type Join = PartialApply; /** * [Fn] Convert a {@link List} to a union type. * * Sig: `(xs: List) => T` */ export type ToUnion = ToUnionFn; } /****************** * Static members * ******************/ /** * [Fn] Create a {@link List} with one element. * * Sig: `(x: T) => List` * * @example * ```typescript * type R1 = $; * // ^?: readonly [1] * type R2 = $; * // ^?: readonly ["foo" | false] * ``` * * @see {@link Tuple$$Of1} if you want a version with more precise function signature. */ export type List$$Create = CreateFn; /** * [Fn] Check if a value is a {@link List} (i.e., fixed-length tuple). * * Sig: `(x: unknown) => boolean` * * @example * ```typescript * type R1 = $; * // ^?: true * type R2 = $; * // ^?: true * type R3 = $; * // ^?: true * type R4 = $; * // ^?: false * type R5 = $; * // ^?: false * ``` */ export type List$$IsList = IsListFn; /** * [Fn] Generate a {@link List} of numbers from `From` to `To` (exclusive). * * Sig: `(from: Int, to: Int) => List` */ export type List$$RangeOf = RangeOfFn; /**************** * Type classes * ****************/ export type { List$$HKT$$Builder, List$$HKT$$Extractor } from "./HKT"; export type { List$$Applicative } from "./Applicative"; export type { List$$Functor } from "./Functor"; export type { List$$Monad } from "./Monad"; export type { List$$Semigroup } from "./Semigroup";