Skip to main content
Module

x/rimbu/mod.ts>List.NonEmpty

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
interface List.NonEmpty
implements List<T>, [Streamable.NonEmpty]<T>
import { type List } from "https://deno.land/x/rimbu@0.14.0/mod.ts";
const { NonEmpty } = List;

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

Examples

Example 1

const l = List.of(1, 3, 2)

Properties

readonly
isEmpty: false

Returns false since this collection is known to be non-empty.

Methods

nonEmpty(): true

Returns true since this collection is known to be non-empty

assumeNonEmpty(): this

Returns a self reference since this collection is known to be non-empty.

asNormal(): List<T>

Returns this collection typed as a 'possibly empty' collection.

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

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

first(): T

Returns the first value of the List.

last(): T

Returns the last value of the List.

take<N extends number>(amount: N): 0 extends N ? List<T> : List.NonEmpty<T>

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

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

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

repeat(amount: number): List.NonEmpty<T>

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

rotate(shiftAmount: number): List.NonEmpty<T>

Returns the non-empty List where the first given shiftAmount of values are removed from this List, and are appended at the end.

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

Returns the non-empty 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.NonEmpty<T>

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

insert(index: number, values: StreamSource<T>): List.NonEmpty<T>

Returns the non-empty List with the given values inserted at the given index.

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

Returns a non-empty 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.NonEmpty<T2>

Returns a non-empty 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.NonEmpty<T2>,
range?: undefined,
reversed?: boolean,
): List.NonEmpty<T2>

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

flatMap<T2>(
flatMapFun: (value: T, index: number) => StreamSource<T2>,
range?: IndexRange,
reversed?: boolean,
): List<T2>
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>
reversed(): List.NonEmpty<T>

Returns the non-empty List in reversed order.

toArray(range?: undefined, reversed?: boolean): ArrayNonEmpty<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.

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