Seq
which represents an ordered indexed list of values.
type Seq.Indexed<T> extends Seq<number, T>, Collection.Indexed<T>
Always returns Seq.Indexed, discarding associated keys and supplying incrementing indices.
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.
Provides an Seq.Indexed of the values provided.
Seq.Indexed.of<T>(...values: Array<T>): Seq.Indexed<T>
Returns the value associated with the provided index, or notSetValue if the index is beyond the bounds of the Collection.
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.
has(key: number): boolean;
True if a value exists within this Collection
, using Immutable.is
to determine equality.
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.
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.
last<NSV>(notSetValue: NSV): T | NSV;
last(): T | undefined;
Deeply converts this Indexed Seq to equivalent native JavaScript Array.
toJS(): Array<DeepCopy<T>>;
Shallowly converts this Indexed Seq to equivalent native JavaScript Array.
toJSON(): Array<T>;
Shallowly converts this collection to an Array.
toArray(): Array<T>;
Shallowly converts this Collection to an Object.
toObject(): { [key: string]: T };
Converts keys to Strings.
Returns Seq.Indexed.
toSeq(): Seq.Indexed<T>;
If this is a collection of [key, value] entry tuples, it will return a Seq.Keyed of those entries.
fromEntrySeq(): Seq.Keyed<unknown, unknown>;
Returns a Seq.Keyed with the same key-value entries as this Collection.Indexed.
toKeyedSeq(): Seq.Keyed<number, T>;
Returns a Seq.Indexed with the same values as this Collection.Indexed.
toIndexedSeq(): Seq.Indexed<T>;
Returns a Seq.Set with the same values as this Collection.Indexed.
toSetSeq(): Seq.Set<T>;
Returns a Collection of the same type with separator
between each item in this Collection.
interpose(separator: T): this;
Returns a Collection of the same type with the provided collections
interleaved into this collection.
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.
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.
zip<U>(other: Collection<unknown, U>): Seq.Indexed<[T, U]>;
zip<U, V>(other: Collection<unknown, U>, other2: Collection<unknown, V>): Seq.Indexed<[T, U, V]>;
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
.
zipAll<U>(other: Collection<unknown, U>): Seq.Indexed<[T, U]>;
zipAll<U, V>(other: Collection<unknown, U>, other2: Collection<unknown, V>): Seq.Indexed<[T, U, V]>;
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.
zipWith<U, Z>(zipper: (value: T, otherValue: U) => Z, otherCollection: Collection<unknown, U>): Collection.Indexed<Z>;
zipWith<U, V, Z>(zipper: (value: T, otherValue: U, thirdValue: V) => Z, otherCollection: Collection<unknown, U>, thirdCollection: Collection<unknown, V>): Seq.Indexed<Z>;
zipWith<Z>(zipper: (...values: Array<unknown>) => Z, ...collections: Array<Collection<unknown, unknown>>): Seq.Indexed<Z>;
Flattens nested Collections.
flatten(depth?: number): Collection<unknown, unknown>;
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>
Returns the first index at which a given value can be found in the Collection, or -1 if it is not present.
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.
lastIndexOf(searchValue: T): number;
Returns the first index in the Collection where a value satisfies the provided predicate function. Otherwise -1 is returned.
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.
findLastIndex(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): number;
Returns the first value for which the predicate
returns true.
find(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): T | undefined;
Returns the last value for which the predicate
returns true.
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.
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.
findLastEntry(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): [number, T] | undefined;
Returns the key for which the predicate
returns true.
findKey(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): number | undefined;
Returns the last key for which the predicate
returns true.
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.
keyOf(searchValue: T): number;
Returns the last key associated with the search value, or undefined.
lastKeyOf(searchValue: T): number;
Returns the maximum value in this collection. If any values are comparatively equivalent, the first one found will be returned.
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.
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.
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.
minBy<C>(comparatorValueMapper: (value: T, key: number, iter: this) => C, comparator?: Comparator<C>): T | undefined;
Returns a new Seq with other collections concatenated to this one.
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Seq.Indexed<T | C>;
Returns a new Seq.Indexed with values passed through a mapper
function.
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.
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.
filter<F extends T>(predicate: (value: T, index: number, iter: this) => value is F, context?: unknown): Seq.Indexed<F>;
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.
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>];
partition<C>(predicate: (this: C, value: T, index: number, iter: this) => unknown, context?: C): [this, this];
[Symbol.iterator](): IterableIterator<T>;
Returns a new Collection with only the values for which the predicate
function returns false.
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.
reverse(): this;
Returns a new sorted Collection, sorted by the natural order of the values.
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.
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.
groupBy<K>(mapper: (value: T) => K): Collection.Indexed<Array<T>>;
Returns true if the Collections are of the same size and all values are equal.
equals(other: unknown): other is this;
Returns a hash code for this Collection.
hashCode(): number;
Returns the value at the given nested path, or notSetValue if any key in the path is not present.
getIn<NSV>(path: Array<string | number>, notSetValue: NSV): T | NSV;
getIn(path: Array<string | number>): T | undefined;
Returns a boolean if the given nested path exists.
hasIn(path: Array<string | number>): boolean;
Returns a new Collection.Indexed with the value at the given index updated to the new value.
update(index: number, updater: (value: T) => T): this;
Converts this Collection.Indexed to a Map. The first value of each entry is used as the key.
toMap(): Collection.Keyed<T, T>;
Converts this Collection.Indexed to an OrderedMap. The first value of each entry is used as the key.
toOrderedMap(): Collection.OrderedKeyed<T, T>;
Converts this Collection.Indexed to a Set.
toSet(): Collection.Set<T>;
Converts this Collection.Indexed to an OrderedSet.
toOrderedSet(): Collection.OrderedSet<T>;
Converts this Collection.Indexed to a List.
toList(): Collection.Indexed<T>;
Converts this Collection.Indexed to a Stack.
toStack(): Collection.Indexed<T>;
Returns an Iterable of the keys in the Collection.
keys(): Iterable<number>;
Returns an Iterable of the values in the Collection.
values(): Iterable<T>;
Returns an Iterable of the [key, value] entries in the Collection.
entries(): Iterable<[number, T]>;
Returns a Seq of the keys in the Collection.
keySeq(): Seq.Indexed<number>;
Returns a Seq of the values in the Collection.
valueSeq(): Seq.Indexed<T>;
Returns a Seq of the [key, value] entries in the Collection.
entrySeq(): Seq.Indexed<[number, T]>;
Calls the provided function for each value in the Collection. Returns the Collection.
forEach(fn: (value: T, index: number, iter: this) => void, context?: unknown): this;
Returns a new Collection.Indexed with the values between the given start and end indices.
slice(begin?: number, end?: number): this;
Returns a new Collection.Indexed with all but the first value.
rest(): this;
Returns a new Collection.Indexed with all but the last value.
butLast(): this;
Returns a new Collection.Indexed with the first n
values removed.
skip(n: number): this;
Returns a new Collection.Indexed with the last n
values removed.
skipLast(n: number): this;
Returns a new Collection.Indexed with values skipped while the predicate
function returns true.
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.
skipUntil(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): this;
Returns a new Collection.Indexed with the first n
values.
take(n: number): this;
Returns a new Collection.Indexed with the last n
values.
takeLast(n: number): this;
Returns a new Collection.Indexed with values taken while the predicate
function returns true.
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.
takeUntil(predicate: (value: T, index: number, iter: this) => boolean, context?: unknown): this;
Returns the accumulated result of calling the provided reducer function for each value in the Collection, from left to right.
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.
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.
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.
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.
join(separator?: string): string;
Returns true if the Collection has no values.
isEmpty(): boolean;
Returns the number of values in the Collection.
count(): number;
Returns a new Collection.Indexed with the number of times each value occurs in the Collection.
countBy(): Collection.Indexed<number>;
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).
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).
;