Seq.Indexed

Seq which represents an ordered indexed list of values.

Method signature

type Seq.Indexed<T> extends Seq<number, T>, Collection.Indexed<T>

Construction

Always returns Seq.Indexed, discarding associated keys and supplying incrementing indices.

Method signature

Seq.Indexed<T>(collection?: Iterable<T> | ArrayLike<T>): Seq.Indexed<T>

Note: Seq.Indexed is a conversion function and not a class, and does not use the new keyword during construction.

Static methods

Provides an Seq.Indexed of the values provided.

Method signature

Seq.Indexed.of<T>(...values: Array<T>): Seq.Indexed<T>

Reading values

Returns the value associated with the provided index, or notSetValue if the index is beyond the bounds of the Collection.

Method signature

get<NSV>(key: number, notSetValue: NSV): T | NSV;
get(key: number): T | undefined;

index may be a negative number, which indexes back from the end of the Collection. s.get(-1) gets the last item in the Collection.

True if a key exists within this Collection, using Immutable.is to determine equality.

Method signature

has(key: number): boolean;

includes()§

Alias:

contains()

True if a value exists within this Collection, using Immutable.is to determine equality.

Method signature

includes(value: T): boolean;

In case the Collection is not empty returns the first element of the Collection. In case the Collection is empty returns the optional default value if provided, if no default value is provided returns undefined.

Method signature

first<NSV>(notSetValue: NSV): T | NSV;
first(): T | undefined;

In case the Collection is not empty returns the last element of the Collection. In case the Collection is empty returns the optional default value if provided, if no default value is provided returns undefined.

Method signature

last<NSV>(notSetValue: NSV): T | NSV;
last(): T | undefined;

Conversion to JavaScript types

Deeply converts this Indexed Seq to equivalent native JavaScript Array.

Method signature

toJS(): Array<DeepCopy<T>>;

Shallowly converts this Indexed Seq to equivalent native JavaScript Array.

Method signature

toJSON(): Array<T>;

Shallowly converts this collection to an Array.

Method signature

toArray(): Array<T>;

Shallowly converts this Collection to an Object.

Method signature

toObject(): { [key: string]: T };

Converts keys to Strings.

Conversion to Seq

Returns Seq.Indexed.

Method signature

toSeq(): Seq.Indexed<T>;

If this is a collection of [key, value] entry tuples, it will return a Seq.Keyed of those entries.

Method signature

fromEntrySeq(): Seq.Keyed<unknown, unknown>;

Returns a Seq.Keyed with the same key-value entries as this Collection.Indexed.

Method signature

toKeyedSeq(): Seq.Keyed<number, T>;

Returns a Seq.Indexed with the same values as this Collection.Indexed.

Method signature

toIndexedSeq(): Seq.Indexed<T>;

Returns a Seq.Set with the same values as this Collection.Indexed.

Method signature

toSetSeq(): Seq.Set<T>;

Combination

Returns a Collection of the same type with separator between each item in this Collection.

Method signature

interpose(separator: T): this;

Returns a Collection of the same type with the provided collections interleaved into this collection.

Method signature

interleave(...collections: Array<Collection<unknown, T>>): this;

The resulting Collection includes the first item from each, then the second from each, etc.

The shortest Collection stops interleave.

Since interleave() re-indexes values, it produces a complete copy, which has O(N) complexity.

Note: interleave cannot be used in withMutations.

Splice returns a new indexed Collection by replacing a region of this Collection with new values. If values are not provided, it only skips the region to be removed.

Method signature

splice(index: number, removeNum: number, ...values: Array<T>): this;

index may be a negative number, which indexes back from the end of the Collection. s.splice(-2) splices after the second to last item.

Since splice() re-indexes values, it produces a complete copy, which has O(N) complexity.

Note: splice cannot be used in withMutations.

Returns a Collection of the same type "zipped" with the provided collections.

Method signature

zip<U>(other: Collection<unknown, U>): Seq.Indexed<[T, U]>;

Method signature

zip<U, V>(other: Collection<unknown, U>, other2: Collection<unknown, V>): Seq.Indexed<[T, U, V]>;

Method signature

zip(...collections: Array<Collection<unknown, unknown>>): Seq.Indexed<unknown>;

Like zipWith, but using the default zipper: creating an Array.

Returns a Collection "zipped" with the provided collections. Unlike zip, zipAll continues zipping until the longest collection is exhausted. Missing values from shorter collections are filled with undefined.

Method signature

zipAll<U>(other: Collection<unknown, U>): Seq.Indexed<[T, U]>;

Method signature

zipAll<U, V>(other: Collection<unknown, U>, other2: Collection<unknown, V>): Seq.Indexed<[T, U, V]>;

Method signature

zipAll(...collections: Array<Collection<unknown, unknown>>): Seq.Indexed<unknown>;

Returns a Collection of the same type "zipped" with the provided collections by using a custom zipper function.

Method signature

zipWith<U, Z>(zipper: (value: T, otherValue: U) => Z, otherCollection: Collection<unknown, U>): Collection.Indexed<Z>;

Method signature

zipWith<U, V, Z>(zipper: (value: T, otherValue: U, thirdValue: V) => Z, otherCollection: Collection<unknown, U>, thirdCollection: Collection<unknown, V>): Seq.Indexed<Z>;

Method signature

zipWith<Z>(zipper: (...values: Array<unknown>) => Z, ...collections: Array<Collection<unknown, unknown>>): Seq.Indexed<Z>;

Flattens nested Collections.

Method signature

flatten(depth?: number): Collection<unknown, unknown>;

Method signature

flatten(shallow?: boolean): Collection<unknown, unknown>;

Will deeply flatten the Collection by default, returning a Collection of the same type, but a depth can be provided in the form of a number or boolean (where true means to shallowly flatten one level). A depth of 0 (or shallow: false) will deeply flatten.

Flattens only others Collection, not Arrays or Objects.

Note: flatten(true) operates on Collection<unknown, Collection<K, V>> and returns Collection<K, V>

Search for value

Returns the first index at which a given value can be found in the Collection, or -1 if it is not present.

Method signature

indexOf(searchValue: T): number;

Returns the last index at which a given value can be found in the Collection, or -1 if it is not present.

Method signature

lastIndexOf(searchValue: T): number;

Returns the first index in the Collection where a value satisfies the provided predicate function. Otherwise -1 is returned.

Method signature

findIndex(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): number;

Returns the last index in the Collection where a value satisfies the provided predicate function. Otherwise -1 is returned.

Method signature

findLastIndex(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): number;

Returns the first value for which the predicate returns true.

Method signature

find(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): T | undefined;

Returns the last value for which the predicate returns true.

Method signature

findLast(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): T | undefined;

Note: predicate will be called for each entry in reverse.

Returns the first [key, value] entry for which the predicate returns true.

Method signature

findEntry(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): [number, T] | undefined;

Returns the last [key, value] entry for which the predicate returns true.

Method signature

findLastEntry(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): [number, T] | undefined;

Returns the key for which the predicate returns true.

Method signature

findKey(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): number | undefined;

Returns the last key for which the predicate returns true.

Method signature

findLastKey(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): number | undefined;

Note: predicate will be called for each entry in reverse.

Returns the key associated with the search value, or undefined.

Method signature

keyOf(searchValue: T): number;

Returns the last key associated with the search value, or undefined.

Method signature

lastKeyOf(searchValue: T): number;

Returns the maximum value in this collection. If any values are comparatively equivalent, the first one found will be returned.

Method signature

max(comparator?: Comparator<T>): T | undefined;

The comparator is used in the same way as Collection#sort. If it is not provided, the default comparator is >.

When two values are considered equivalent, the first encountered will be returned. Otherwise, max will operate independent of the order of input as long as the comparator is commutative. The default comparator > is commutative only when types do not differ.

If comparator returns 0 and either value is NaN, undefined, or null, that value will be returned.

Like max, but also accepts a comparatorValueMapper which allows for comparing by more sophisticated means.

Method signature

maxBy<C>(comparatorValueMapper: (value: T, key: number, iter: this) => C, comparator?: Comparator<C>): T | undefined;

Returns the minimum value in this collection. If any values are comparatively equivalent, the first one found will be returned.

Method signature

min(comparator?: Comparator<T>): T | undefined;

The comparator is used in the same way as Collection#sort. If it is not provided, the default comparator is <.

When two values are considered equivalent, the first encountered will be returned. Otherwise, min will operate independent of the order of input as long as the comparator is commutative. The default comparator < is commutative only when types do not differ.

If comparator returns 0 and either value is NaN, undefined, or null, that value will be returned.

Like min, but also accepts a comparatorValueMapper which allows for comparing by more sophisticated means.

Method signature

minBy<C>(comparatorValueMapper: (value: T, key: number, iter: this) => C, comparator?: Comparator<C>): T | undefined;

Sequence algorithms

Returns a new Seq with other collections concatenated to this one.

Method signature

concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Seq.Indexed<T | C>;

Returns a new Seq.Indexed with values passed through a mapper function.

Method signature

map<M>(mapper: (value: T, key: number, iter: this) => M, context?: unknown): Seq.Indexed<M>;

Note: map() always returns a new instance, even if it produced the same value at every step.

Flat-maps the Seq, returning a Seq of the same type.

Method signature

flatMap<M>(mapper: (value: T, key: number, iter: this) => Iterable<M>, context?: unknown): Seq.Indexed<M>;

Similar to seq.map(...).flatten(true).

Returns a new Collection with only the values for which the predicate function returns true.

Method signature

filter<F extends T>(predicate: (value: T, index: number, iter: this) => value is F, context?: unknown): Seq.Indexed<F>;

Method signature

filter(predicate: (value: T, index: number, iter: this) => unknown, context?: unknown): this;

Note: filter() always returns a new instance, even if it results in not filtering out any values.

Returns a new indexed Seq with the values for which the predicate function returns false and another for which is returns true.

Method signature

partition<F extends T, C>(predicate: (this: C, value: T, index: number, iter: this) => value is F, context?: C): [Seq.Indexed<T>, Seq.Indexed<F>];

Method signature

partition<C>(predicate: (this: C, value: T, index: number, iter: this) => unknown, context?: C): [this, this];

Method signature

[Symbol.iterator](): IterableIterator<T>;

Returns a new Collection with only the values for which the predicate function returns false.

Method signature

filterNot(predicate: (value: T, index: number, iter: this) => unknown, context?: unknown): this;

Note: filterNot() always returns a new instance, even if it results in not filtering out any values.

Returns a new Collection with the values in reverse order.

Method signature

reverse(): this;

Returns a new sorted Collection, sorted by the natural order of the values.

Method signature

sort(): Collection.Indexed<T>;

If a comparator is not provided, a default comparator uses < and >.

Note: sort() always returns a new instance, even if the original was already sorted.

Note: This is always an eager operation.

Returns a new sorted Collection, sorted by the provided comparator function.

Method signature

sortBy<R>(comparator: (value: T) => R): Collection.Indexed<T>;

Note: sortBy() always returns a new instance, even if the original was already sorted.

Note: This is always an eager operation.

Groups the values by the return value of the mapper function, and returns a Collection.Indexed of Arrays of grouped values.

Method signature

groupBy<K>(mapper: (value: T) => K): Collection.Indexed<Array<T>>;

Value equality

Returns true if the Collections are of the same size and all values are equal.

Method signature

equals(other: unknown): other is this;

Returns a hash code for this Collection.

Method signature

hashCode(): number;

Reading deep values

Returns the value at the given nested path, or notSetValue if any key in the path is not present.

Method signature

getIn<NSV>(path: Array<string | number>, notSetValue: NSV): T | NSV;

Method signature

getIn(path: Array<string | number>): T | undefined;

Returns a boolean if the given nested path exists.

Method signature

hasIn(path: Array<string | number>): boolean;

Persistent changes

Returns a new Collection.Indexed with the value at the given index updated to the new value.

Method signature

update(index: number, updater: (value: T) => T): this;

Conversion to Collections

Converts this Collection.Indexed to a Map. The first value of each entry is used as the key.

Method signature

toMap(): Collection.Keyed<T, T>;

Converts this Collection.Indexed to an OrderedMap. The first value of each entry is used as the key.

Method signature

toOrderedMap(): Collection.OrderedKeyed<T, T>;

Converts this Collection.Indexed to a Set.

Method signature

toSet(): Collection.Set<T>;

Converts this Collection.Indexed to an OrderedSet.

Method signature

toOrderedSet(): Collection.OrderedSet<T>;

Converts this Collection.Indexed to a List.

Method signature

toList(): Collection.Indexed<T>;

Converts this Collection.Indexed to a Stack.

Method signature

toStack(): Collection.Indexed<T>;

Iterators

Returns an Iterable of the keys in the Collection.

Method signature

keys(): Iterable<number>;

Returns an Iterable of the values in the Collection.

Method signature

values(): Iterable<T>;

Returns an Iterable of the [key, value] entries in the Collection.

Method signature

entries(): Iterable<[number, T]>;

Collections (Seq)

Returns a Seq of the keys in the Collection.

Method signature

keySeq(): Seq.Indexed<number>;

Returns a Seq of the values in the Collection.

Method signature

valueSeq(): Seq.Indexed<T>;

Returns a Seq of the [key, value] entries in the Collection.

Method signature

entrySeq(): Seq.Indexed<[number, T]>;

Side effects

Calls the provided function for each value in the Collection. Returns the Collection.

Method signature

forEach(fn: (value: T, index: number, iter: this) => void, context?: unknown): this;

Creating subsets

Returns a new Collection.Indexed with the values between the given start and end indices.

Method signature

slice(begin?: number, end?: number): this;

Returns a new Collection.Indexed with all but the first value.

Method signature

rest(): this;

Returns a new Collection.Indexed with all but the last value.

Method signature

butLast(): this;

Returns a new Collection.Indexed with the first n values removed.

Method signature

skip(n: number): this;

Returns a new Collection.Indexed with the last n values removed.

Method signature

skipLast(n: number): this;

Returns a new Collection.Indexed with values skipped while the predicate function returns true.

Method signature

skipWhile(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): this;

Returns a new Collection.Indexed with values skipped until the predicate function returns true.

Method signature

skipUntil(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): this;

Returns a new Collection.Indexed with the first n values.

Method signature

take(n: number): this;

Returns a new Collection.Indexed with the last n values.

Method signature

takeLast(n: number): this;

Returns a new Collection.Indexed with values taken while the predicate function returns true.

Method signature

takeWhile(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): this;

Returns a new Collection.Indexed with values taken until the predicate function returns true.

Method signature

takeUntil(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): this;

Reducing a value

Returns the accumulated result of calling the provided reducer function for each value in the Collection, from left to right.

Method signature

reduce<R>(reducer: (previousValue: R | T, currentValue: T, index: number, iter: this) => R, initialValue?: R): R;

Returns the accumulated result of calling the provided reducer function for each value in the Collection, from right to left.

Method signature

reduceRight<R>(reducer: (previousValue: R | T, currentValue: T, index: number, iter: this) => R, initialValue?: R): R;

Returns true if the predicate function returns a truthy value for every value in the Collection.

Method signature

every(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): boolean;

Returns true if the predicate function returns a truthy value for any value in the Collection.

Method signature

some(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): boolean;

Returns the concatenated string result of calling String(value) on every value in the Collection, separated by the given separator string.

Method signature

join(separator?: string): string;

Returns true if the Collection has no values.

Method signature

isEmpty(): boolean;

Returns the number of values in the Collection.

Method signature

count(): number;

Returns a new Collection.Indexed with the number of times each value occurs in the Collection.

Method signature

countBy(): Collection.Indexed<number>;

Comparison

Returns true if this Collection.Indexed is a subset of the other Collection (i.e. all values in this Collection.Indexed are also in the other).

Method signature

isSubset(other: unknown): other is this;

Returns true if this Collection.Indexed is a superset of the other Collection (i.e. this Collection.Indexed contains all values of the other).

;