Skip to main content

namespace List

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

Companion interface: List<T>

Interfaces​

NameDescription
List.Builder<T>A mutable builder to create immutable List instances in a more efficient way. See the List documentation and the List.Builder API documentation
List.ContextA context instance for List that acts as a factory for every instance of this type of collection.
List.NonEmpty<T>A non-empty random accessible immutable sequence of values of type T. See the List documentation and the List API documentation
List.TypesA utility interface to extract related List types.

Static Methods​

builder​

Returns an empty List Builder based on this context.

Definition​

builder<T>(): List.Builder<T>;

Type parameters​

NameDescription
Tthe List element type
example
List.builder<number>()   // => List.Builder<number>

Overrides​

ListFactory.builder

createContext​

Returns a new List.Creators instance using the provided options.

Definition​

createContext(options?: {
    blockSizeBits?: number;
  }): List.Context;

Parameters​

NameTypeDescription
options{
    blockSizeBits?: number;
  }
(optional) an object containing the following properties:

defaultContext​

Returns the default List.Context instance.

Definition​

defaultContext(): List.Context;

empty​

Returns the (singleton) empty List for this context with given value type.

Definition​

empty<T>(): List<T>;

Type parameters​

NameDescription
Tthe element type
example
List.empty<number>()    // => List<number>
List.empty<string>() // => List<string>

Overrides​

ListFactory.empty

flatten​

Returns, if T is a valid StreamSource, the result of concatenating all streamable elements of the given sources.

Definitions​

flatten<T extends StreamSource.NonEmpty<unknown>>(source: StreamSource.NonEmpty<T>): T extends StreamSource.NonEmpty<infer S> ? List.NonEmpty<S> : never;

flatten<T extends StreamSource<unknown>>(source: StreamSource<T>): T extends StreamSource<infer S> ? List<S> : never;

Type parameters​

NameConstraintsDescription
TStreamSource.NonEmpty<unknown>the element type

Parameters​

NameTypeDescription
sourceStreamSource.NonEmpty<T>a StreamSource containing StreamSource instances of values to concatenate
example
const m = List.of([1, 2], [3, 4, 5])
List.flatten(m).toArray() // => [1, 2, 3, 4, 5]

Overrides​

ListFactory.flatten

from​

Returns an immutable List of this collection type and context, containing the given values in sources.

Definitions​

from<T>(...sources: ArrayNonEmpty<StreamSource.NonEmpty<T>>): List.NonEmpty<T>;

from<T>(...sources: ArrayNonEmpty<StreamSource<T>>): List<T>;

Type parameters​

NameDescription
Tthe element type

Parameters​

NameTypeDescription
sourcesArrayNonEmpty<StreamSource.NonEmpty<T>>a non-empty array of StreamSource instances containing values
example
List.from([1, 2, 3], [4, 5]).toArray()
// => [1, 2, 3, 4, 5]

Overrides​

ListFactory.from

fromString​

Returns a List of characters from the given strings in sources.

Definitions​

fromString<S extends string>(...sources: ArrayNonEmpty<StringNonEmpty<S>>): List.NonEmpty<string>;

fromString(...sources: ArrayNonEmpty<string>): List<string>;

Type parameters​

NameConstraintsDescription
Sstringthe source string type

Parameters​

NameTypeDescription
sourcesArrayNonEmpty<StringNonEmpty<S>>a non-empty array containing strings
example
List.fromString('abc').toArray()   // => ['a', 'b', 'c']

Overrides​

ListFactory.fromString

of​

Returns an immutable List of this type and context, containing the given values.

Definition​

of<T>(...values: ArrayNonEmpty<T>): List.NonEmpty<T>;

Type parameters​

NameDescription
Tthe element type

Parameters​

NameTypeDescription
valuesArrayNonEmpty<T>a non-empty array of values
example
List.of(1, 2, 3).toArray()   // => [1, 2, 3]

Overrides​

ListFactory.of

reducer​

Returns a Reducer that appends received items to a List and returns the List as a result. When a source is given, the reducer will first create a List from the source, and then append elements to it.

Definition​

reducer<T>(source?: StreamSource<T>): Reducer<T, List<T>>;

Type parameters​

NameDescription
Tthe element type

Parameters​

NameTypeDescription
sourceStreamSource<T>(optional) an initial source of elements to append to
example
const someList = List.of(1, 2, 3);
const result = Stream.range({ start: 20, amount: 5 }).reduce(List.reducer(someList))
result.toArray() // => [1, 2, 3, 20, 21, 22, 23, 24]
note

uses a List builder under the hood. If the given source is a List in the same context, it will directly call .toBuilder().

Overrides​

ListFactory.reducer

unzip​

Returns an array of Lists, where each list contains the values of the corresponding index of tuple T.

Definitions​

unzip<T extends readonly unknown[] & {
    length: L;
  }, L extends number>(source: StreamSource.NonEmpty<T>, options: {
    length: L;
  }): {
    [K in keyof T]: List.NonEmpty<T[K]>;
  };

unzip<T extends readonly unknown[] & {
    length: L;
  }, L extends number>(source: StreamSource<T>, options: {
    length: L;
  }): {
    [K in keyof T]: List<T[K]>;
  };

Type parameters​

NameConstraintsDescription
Treadonly unknown[] & {
    length: L;
  }
the StreamSource tuple element type
Lnumberthe tuple element length

Parameters​

NameTypeDescription
sourceStreamSource.NonEmpty<T>a StreamSource containing tuples of type T to unzip
options{
    length: L;
  }
an object containing the following properties:
- length: the length of the tuples in type T
example
const m = List.of([1, 'a'], [2, 'b'])
List.unzip(m) // => [List.NonEmpty<number>, List.NonEmpty<string>]

Overrides​

ListFactory.unzip