Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/list/main/index.ts>List

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
namespace List
import { List } from "https://deno.land/x/rimbu@0.14.0/list/main/index.ts";

Interfaces

A mutable builder to create immutable List instances in a more efficient way. See the List documentation and the List.Builder API documentation

A context instance for List that acts as a factory for every instance of this type of collection.

A non-empty random accessible immutable sequence of values of type T. See the List documentation and the List API documentation

A utility interface to extract related List types.

interface List
implements FastIterable<T>
import { type List } from "https://deno.land/x/rimbu@0.14.0/list/main/index.ts";

A random accessible immutable sequence of values of type T. See the List documentation and the List API documentation

Examples

Example 1

const l1 = List.empty<string>()
const l2 = List.of(1, 3, 2)

Properties

readonly
context: List.Context

The list context that acts as a factory for all related list instances.

readonly
length: number

Returns the number of values in the collection

readonly
isEmpty: boolean

Returns true if the collection is empty

Methods

nonEmpty(): this is List.NonEmpty<T>

Returns true if there is at least one value in the collection, and instructs the compiler to treat the collection as a .NonEmpty type.

assumeNonEmpty(): List.NonEmpty<T>

Returns the same collection typed as non-empty.

stream(reversed?: boolean): Stream<T>

Returns a Stream containing the values in order of the List, or in reverse order if reversed is true.

streamRange(range: IndexRange, reversed?: boolean): Stream<T>

Returns a Stream containing the values contained in the given index range, in order of the List, or in reverse order if reversed is true.

first(): T | undefined

Returns the first value of the List, or the otherwise value if the list is empty.

first<O>(otherwise: OptLazy<O>): T | O
last(): T | undefined

Returns the last value of the List, or the otherwise value if the list is empty.

last<O>(otherwise: OptLazy<O>): T | O
get(index: number): T | undefined

Returns the value in the List at the given index.

get<O>(index: number, otherwise: OptLazy<O>): T | O
prepend(value: T): List.NonEmpty<T>

Returns the List with the given value added to the start.

append(value: T): List.NonEmpty<T>

Returns the List with the given value added to the end.

take(amount: number): List<T>

Returns a List containing the first (or last) given amount values of this List.

drop(amount: number): List<T>

Returns a List skipping the first given amount elements of this List.

slice(range: IndexRange, reversed?: boolean): List<T>

Returns the List containing the values within the given index range, potentially reversed in order if reversed is true.

splice(options: { index: number; remove?: number; insert: StreamSource.NonEmpty<T>; }): List.NonEmpty<T>

Returns the List, where at the given index the remove amount of values are replaced by the values from the optionally given insert StreamSource.

splice(options: { index: number; remove?: number; insert?: StreamSource<T>; }): List<T>
insert(index: number, values: StreamSource.NonEmpty<T>): List.NonEmpty<T>

Returns the List with the given values inserted at the given index.

insert(index: number, values: StreamSource<T>): List<T>
remove(index: number, amount?: number): List<T>

Returns the List with the given amount of values removed at the given index.

concat<T2 = T>(...sources: ArrayNonEmpty<StreamSource.NonEmpty<T2>>): List.NonEmpty<T | T2>

Returns the List succeeded by the values from all given StreamSource instances given in sources.

concat<T2 = T>(...sources: ArrayNonEmpty<StreamSource<T2>>): List<T | T2>
repeat(amount: number): List<T>

Returns a List that contains this List the given amount of times.

rotate(shiftRightAmount: number): List<T>

Returns the List where the elements are shifted to right by shiftRoundAmount position, and the elements at the end are placed at the beginning.

padTo(
length: number,
fill: T,
positionPercentage?: number,
): List<T>

Returns the List where, if given length is larger than the List length, the given fill value is added to the start and/or end of the List according to the positionPercentage such that the result length is equal to length.

updateAt(index: number, update: Update<T>): List<T>

Returns the List where at the given index the value is replaced or updated by the given update.

filter(
pred: (
value: T,
index: number,
halt: () => void,
) => boolean
,
range?: IndexRange,
reversed?: boolean,
): List<T>

Returns a List containing only those values within optionally given range that satisfy given pred predicate. If reversed is true, the order of the values is reversed.

collect<T2>(
collectFun: CollectFun<T, T2>,
range?: IndexRange,
reversed?: boolean,
): List<T2>

Returns a List containing the values resulting from applying given collectFun to each value in this List.

forEach(f: (
value: T,
index: number,
halt: () => void,
) => void
, state?: TraverseState
): void

Performs given function f for each value of the List.

map<T2>(mapFun: (value: T, index: number) => T2, reversed?: boolean): List<T2>

Returns a List containing the result of applying given mapFun to each value in this List. If reversed is true, the order of the values is reversed.

mapPure<T2>(mapFun: (value: T) => T2, reversed?: boolean): List<T2>

Returns a List containing the result of applying given mapFun to each value in this List. If reversed is true, the order of the values is reversed.

flatMap<T2>(
flatMapFun: (value: T, index: number) => StreamSource<T2>,
range?: IndexRange,
reversed?: boolean,
): List<T2>

Returns a List containing the joined results of applying given flatMapFun to each value in this List.

reversed(): List<T>

Returns the List in reversed order.

toArray(range?: IndexRange, reversed?: boolean): T[]

Returns an array containing the values within given range (default: all) in this collection. If reversed is true, reverses the order of the values.

toBuilder(): List.Builder<T>

Returns a builder object containing the values of this collection.

toString(): string

Returns a string representation of this collection.

toJSON(): ToJSON<T[], this["context"]["typeTag"]>

Returns a JSON representation of this collection.

variable List
import { List } from "https://deno.land/x/rimbu@0.14.0/list/main/index.ts";