Seq
which represents an ordered indexed list of values.
type Seq.Indexed<T> extends Seq<number, T>, Iterable.Indexed<T>
Seq.Indexed<T>(): Seq.Indexed<T>
Seq.Indexed<T>(seq: Iterable.Indexed<T>): Seq.Indexed<T>
Seq.Indexed<T>(seq: Iterable.Set<T>): Seq.Indexed<T>
Seq.Indexed<K, V>(seq: Iterable.Keyed<K, V>): Seq.Indexed<any>
Seq.Indexed<T>(array: Array<T>): Seq.Indexed<T>
Seq.Indexed<T>(iterator: Iterator<T>): Seq.Indexed<T>
Seq.Indexed<T>(iterable: Object): Seq.Indexed<T>
Seq.Indexed.of<T>(...values: T[]): Seq.Indexed<T>
Returns a Seq.Keyed from this Iterable where indices are treated as keys.
toKeyedSeq(): Seq.Keyed<number, T>
Iterable#toKeyedSeq()
This is useful if you want to operate on an Iterable.Indexed and preserve the [index, value] pairs.
The returned Seq will have identical iteration order as this Iterable.
Example:
var indexedSeq = Immutable.Seq.of('A', 'B', 'C');
indexedSeq.filter(v => v === 'B').toString() // Seq [ 'B' ]
var keyedSeq = indexedSeq.toKeyedSeq();
keyedSeq.filter(v => v === 'B').toString() // Seq { 1: 'B' }
Returns an Seq.Indexed of the values of this Iterable, discarding keys.
toIndexedSeq(): Seq.Indexed<T>
Iterable#toIndexedSeq()
Returns a Seq.Set of the values of this Iterable, discarding keys.
toSetSeq(): Seq.Set<T>
Iterable#toSetSeq()
If this is an iterable of [key, value] entry tuples, it will return a Seq.Keyed of those entries.
fromEntrySeq(): Seq.Keyed<any, any>
Iterable.Indexed#fromEntrySeq()
Some Seqs can describe their size lazily. When this is the case, size will be an integer. Otherwise it will be undefined.
size: number
Seq#size
Because Sequences are lazy and designed to be chained together, they do
not cache their results. For example, this map function is called a total
of 6 times, as each join
iterates the Seq of three values.
cacheResult(): Seq<number, T>
Seq#cacheResult()
var squares = Seq.of(1,2,3).map(x => x x);
squares.join() + squares.join();
If you know a Seq
will be used multiple times, it may be more
efficient to first cache it in memory. Here, the map function is called
only 3 times.
var squares = Seq.of(1,2,3).map(x => x x).cacheResult();
squares.join() + squares.join();
Use this method judiciously, as it must fully evaluate a Seq which can be a burden on memory and possibly performance.
Note: after calling cacheResult
, a Seq will always have a size
.
True if this and the other Iterable have value equality, as defined
by Immutable.is()
.
equals(other: Iterable<number, T>): boolean
Iterable#equals()
Note: This is equivalent to Immutable.is(this, other)
, but provided to
allow for chained expressions.
Computes and returns the hashed identity for this Iterable.
hashCode(): number
Iterable#hashCode()
The hashCode
of an Iterable is used to determine potential equality,
and is used when adding this to a Set
or as a key in a Map
, enabling
lookup via a different instance.
var a = List.of(1, 2, 3);
var b = List.of(1, 2, 3);
assert(a !== b); // different instances
var set = Set.of(a);
assert(set.has(b) === true);
If two values have the same hashCode
, they are not guaranteed
to be equal. If two values have different hashCode
s,
they must not be equal.
Returns the value associated with the provided key, or notSetValue if the Iterable does not contain this key.
get(key: number, notSetValue?: T): T
Iterable#get()
Note: it is possible a key may be associated with an undefined
value,
so if notSetValue
is not provided and this method returns undefined
,
that does not guarantee the key was not found.
True if a key exists within this Iterable
, using Immutable.is
to determine equality
has(key: number): boolean
Iterable#has()
True if a value exists within this Iterable
, using Immutable.is
to determine equality
includes(value: T): boolean
Iterable#includes()
contains()
getIn(searchKeyPath: Array<any>, notSetValue?: any): any
getIn(searchKeyPath: Iterable<any, any>, notSetValue?: any): any
Iterable#getIn()
hasIn(searchKeyPath: Array<any>): boolean
hasIn(searchKeyPath: Iterable<any, any>): boolean
Iterable#hasIn()
Deeply converts this Iterable to equivalent JS.
toJS(): any
Iterable#toJS()
toJSON()
Iterable.Indexeds
, and Iterable.Sets
become Arrays, while
Iterable.Keyeds
become Objects.
Shallowly converts this iterable to an Array, discarding keys.
toArray(): Array<T>
Iterable#toArray()
Shallowly converts this Iterable to an Object.
toObject(): {[key: string]: T}
Iterable#toObject()
Throws if keys are not strings.
Converts this Iterable to a Map, Throws if keys are not hashable.
toMap(): Map<number, T>
Iterable#toMap()
Note: This is equivalent to Map(this.toKeyedSeq())
, but provided
for convenience and to allow for chained expressions.
Converts this Iterable to a Map, maintaining the order of iteration.
toOrderedMap(): OrderedMap<number, T>
Iterable#toOrderedMap()
Note: This is equivalent to OrderedMap(this.toKeyedSeq())
, but
provided for convenience and to allow for chained expressions.
Converts this Iterable to a Set, discarding keys. Throws if values are not hashable.
toSet(): Set<T>
Iterable#toSet()
Note: This is equivalent to Set(this)
, but provided to allow for
chained expressions.
Converts this Iterable to a Set, maintaining the order of iteration and discarding keys.
toOrderedSet(): OrderedSet<T>
Iterable#toOrderedSet()
Note: This is equivalent to OrderedSet(this.valueSeq())
, but provided
for convenience and to allow for chained expressions.
Converts this Iterable to a List, discarding keys.
toList(): List<T>
Iterable#toList()
Note: This is equivalent to List(this)
, but provided to allow
for chained expressions.
Converts this Iterable to a Stack, discarding keys. Throws if values are not hashable.
toStack(): Stack<T>
Iterable#toStack()
Note: This is equivalent to Stack(this)
, but provided to allow for
chained expressions.
An iterator of this Iterable
's keys.
keys(): Iterator<number>
Iterable#keys()
Note: this will return an ES6 iterator which does not support Immutable JS sequence algorithms. Use keySeq
instead, if this is what you want.
An iterator of this Iterable
's values.
values(): Iterator<T>
Iterable#values()
Note: this will return an ES6 iterator which does not support Immutable JS sequence algorithms. Use valueSeq
instead, if this is what you want.
An iterator of this Iterable
's entries as [key, value]
tuples.
entries(): Iterator<Array<any>>
Iterable#entries()
Note: this will return an ES6 iterator which does not support Immutable JS sequence algorithms. Use entrySeq
instead, if this is what you want.
Returns a new Seq.Indexed of the keys of this Iterable, discarding values.
keySeq(): Seq.Indexed<number>
Iterable#keySeq()
Returns an Seq.Indexed of the values of this Iterable, discarding keys.
valueSeq(): Seq.Indexed<T>
Iterable#valueSeq()
Returns a new Seq.Indexed of [key, value] tuples.
entrySeq(): Seq.Indexed<Array<any>>
Iterable#entrySeq()
Returns a new Iterable of the same type with values passed through a
mapper
function.
map<M>(mapper: (value?: T, key?: number, iter?: Iterable<number, T>) => M,
context?: any): Iterable<number, M>
Iterable#map()
Seq({ a: 1, b: 2 }).map(x => 10 * x)
// Seq { a: 10, b: 20 }
Returns a new Iterable of the same type with only the entries for which
the predicate
function returns true.
filter(predicate: (value?: T, key?: number, iter?: Iterable<number, T>) => boolean,
context?: any): Iterable<number, T>
Iterable#filter()
Seq({a:1,b:2,c:3,d:4}).filter(x => x % 2 === 0)
// Seq { b: 2, d: 4 }
Returns a new Iterable of the same type with only the entries for which
the predicate
function returns false.
filterNot(predicate: (value?: T, key?: number, iter?: Iterable<number, T>) => boolean,
context?: any): Iterable<number, T>
Iterable#filterNot()
Seq({a:1,b:2,c:3,d:4}).filterNot(x => x % 2 === 0)
// Seq { a: 1, c: 3 }
Returns a new Iterable of the same type in reverse order.
reverse(): Iterable<number, T>
Iterable#reverse()
Returns a new Iterable of the same type which includes the same entries,
stably sorted by using a comparator
.
sort(comparator?: (valueA: T, valueB: T) => number): Iterable<number, T>
Iterable#sort()
If a comparator
is not provided, a default comparator uses <
and >
.
comparator(valueA, valueB)
:
0
if the elements should not be swapped.-1
(or any negative number) if valueA
comes before valueB
1
(or any positive number) if valueA
comes after valueB
When sorting collections which have no defined order, their ordered
equivalents will be returned. e.g. map.sort()
returns OrderedMap.
Like sort
, but also accepts a comparatorValueMapper
which allows for
sorting by more sophisticated means:
sortBy<C>(comparatorValueMapper: (value?: T,
key?: number,
iter?: Iterable<number, T>) => C,
comparator?: (valueA: C, valueB: C) => number): Iterable<number, T>
Iterable#sortBy()
hitters.sortBy(hitter => hitter.avgHits);
Returns a Iterable.Keyed
of Iterable.Keyeds
, grouped by the return
value of the grouper
function.
groupBy<G>(grouper: (value?: T, key?: number, iter?: Iterable<number, T>) => G,
context?: any): Seq.Keyed<G, Iterable<number, T>>
Iterable#groupBy()
Note: This is always an eager operation.
The sideEffect
is executed for every entry in the Iterable.
forEach(sideEffect: (value?: T, key?: number, iter?: Iterable<number, T>) => any,
context?: any): number
Iterable#forEach()
Unlike Array#forEach
, if any call of sideEffect
returns
false
, the iteration will stop. Returns the number of entries iterated
(including the last iteration which returned false).
Returns a new Iterable of the same type representing a portion of this Iterable from start up to but not including end.
slice(begin?: number, end?: number): Iterable<number, T>
Iterable#slice()
If begin is negative, it is offset from the end of the Iterable. e.g.
slice(-2)
returns a Iterable of the last two entries. If it is not
provided the new Iterable will begin at the beginning of this Iterable.
If end is negative, it is offset from the end of the Iterable. e.g.
slice(0, -1)
returns an Iterable of everything but the last entry. If
it is not provided, the new Iterable will continue through the end of
this Iterable.
If the requested slice is equivalent to the current Iterable, then it will return itself.
Returns a new Iterable of the same type containing all entries except the first.
rest(): Iterable<number, T>
Iterable#rest()
Returns a new Iterable of the same type containing all entries except the last.
butLast(): Iterable<number, T>
Iterable#butLast()
Returns a new Iterable of the same type which excludes the first amount
entries from this Iterable.
skip(amount: number): Iterable<number, T>
Iterable#skip()
Returns a new Iterable of the same type which excludes the last amount
entries from this Iterable.
skipLast(amount: number): Iterable<number, T>
Iterable#skipLast()
Returns a new Iterable of the same type which includes entries starting
from when predicate
first returns false.
skipWhile(predicate: (value?: T, key?: number, iter?: Iterable<number, T>) => boolean,
context?: any): Iterable<number, T>
Iterable#skipWhile()
Seq.of('dog','frog','cat','hat','god')
.skipWhile(x => x.match(/g/))
// Seq [ 'cat', 'hat', 'god' ]
Returns a new Iterable of the same type which includes entries starting
from when predicate
first returns true.
skipUntil(predicate: (value?: T, key?: number, iter?: Iterable<number, T>) => boolean,
context?: any): Iterable<number, T>
Iterable#skipUntil()
Seq.of('dog','frog','cat','hat','god')
.skipUntil(x => x.match(/hat/))
// Seq [ 'hat', 'god' ]
Returns a new Iterable of the same type which includes the first amount
entries from this Iterable.
take(amount: number): Iterable<number, T>
Iterable#take()
Returns a new Iterable of the same type which includes the last amount
entries from this Iterable.
takeLast(amount: number): Iterable<number, T>
Iterable#takeLast()
Returns a new Iterable of the same type which includes entries from this
Iterable as long as the predicate
returns true.
takeWhile(predicate: (value?: T, key?: number, iter?: Iterable<number, T>) => boolean,
context?: any): Iterable<number, T>
Iterable#takeWhile()
Seq.of('dog','frog','cat','hat','god')
.takeWhile(x => x.match(/o/))
// Seq [ 'dog', 'frog' ]
Returns a new Iterable of the same type which includes entries from this
Iterable as long as the predicate
returns false.
takeUntil(predicate: (value?: T, key?: number, iter?: Iterable<number, T>) => boolean,
context?: any): Iterable<number, T>
Iterable#takeUntil()
Seq.of('dog','frog','cat','hat','god').takeUntil(x => x.match(/at/))
// ['dog', 'frog']
Returns a new Iterable of the same type with other values and iterable-like concatenated to this one.
concat(...valuesOrIterables: any[]): Iterable<number, T>
Iterable#concat()
For Seqs, all entries will be present in the resulting iterable, even if they have the same key.
flatten(depth?: number): Iterable<any, any>
flatten(shallow?: boolean): Iterable<any, any>
Iterable#flatten()
flatMap<MK, MV>(mapper: (value?: T,
key?: number,
iter?: Iterable<number, T>) => Iterable<MK, MV>,
context?: any): Iterable<MK, MV>
flatMap<MK, MV>(mapper: (value?: T, key?: number, iter?: Iterable<number, T>) => any,
context?: any): Iterable<MK, MV>
Iterable#flatMap()
Returns an Iterable of the same type with separator
between each item
in this Iterable.
interpose(separator: T): Iterable.Indexed<T>
Iterable.Indexed#interpose()
Returns an Iterable of the same type with the provided iterables
interleaved into this iterable.
interleave(...iterables: Array<Iterable<any, T>>): Iterable.Indexed<T>
Iterable.Indexed#interleave()
The resulting Iterable includes the first item from each, then the second from each, etc.
I.Seq.of(1,2,3).interleave(I.Seq.of('A','B','C'))
// Seq [ 1, 'A', 2, 'B', 3, 'C' ]
The shortest Iterable stops interleave.
I.Seq.of(1,2,3).interleave(
I.Seq.of('A','B'),
I.Seq.of('X','Y','Z')
)
// Seq [ 1, 'A', 'X', 2, 'B', 'Y' ]
Splice returns a new indexed Iterable by replacing a region of this Iterable with new values. If values are not provided, it only skips the region to be removed.
splice(index: number, removeNum: number, ...values: any[]): Iterable.Indexed<T>
Iterable.Indexed#splice()
index
may be a negative number, which indexes back from the end of the
Iterable. s.splice(-2)
splices after the second to last item.
Seq(['a','b','c','d']).splice(1, 2, 'q', 'r', 's')
// Seq ['a', 'q', 'r', 's', 'd']
Returns an Iterable of the same type "zipped" with the provided iterables.
zip(...iterables: Array<Iterable<any, any>>): Iterable.Indexed<any>
Iterable.Indexed#zip()
zipWith<U, Z>(): Iterable.Indexed<Z>
zipWith<U, V, Z>(zipper: (value: T, otherValue: U, thirdValue: V) => Z,
otherIterable: Iterable<any, U>,
thirdIterable: Iterable<any, V>): Iterable.Indexed<Z>
zipWith<Z>(zipper: (...any: Array<any>) => Z,
...iterables: Array<Iterable<any, any>>): Iterable.Indexed<Z>
Iterable.Indexed#zipWith()
Reduces the Iterable to a value by calling the reducer
for every entry
in the Iterable and passing along the reduced value.
reduce<R>(reducer: (reduction?: R,
value?: T,
key?: number,
iter?: Iterable<number, T>) => R,
initialReduction?: R,
context?: any): R
Iterable#reduce()
If initialReduction
is not provided, or is null, the first item in the
Iterable will be used.
Reduces the Iterable in reverse (from the right side).
reduceRight<R>(reducer: (reduction?: R,
value?: T,
key?: number,
iter?: Iterable<number, T>) => R,
initialReduction?: R,
context?: any): R
Iterable#reduceRight()
Note: Similar to this.reverse().reduce(), and provided for parity
with Array#reduceRight
.
True if predicate
returns true for all entries in the Iterable.
every(predicate: (value?: T, key?: number, iter?: Iterable<number, T>) => boolean,
context?: any): boolean
Iterable#every()
True if predicate
returns true for any entry in the Iterable.
some(predicate: (value?: T, key?: number, iter?: Iterable<number, T>) => boolean,
context?: any): boolean
Iterable#some()
Joins values together as a string, inserting a separator between each.
The default separator is ","
.
join(separator?: string): string
Iterable#join()
Returns true if this Iterable includes no values.
isEmpty(): boolean
Iterable#isEmpty()
count(): number
count(predicate: (value?: T, key?: number, iter?: Iterable<number, T>) => boolean,
context?: any): number
Iterable#count()
Returns a Seq.Keyed
of counts, grouped by the return value of
the grouper
function.
countBy<G>(grouper: (value?: T, key?: number, iter?: Iterable<number, T>) => G,
context?: any): Map<G, number>
Iterable#countBy()
Note: This is not a lazy operation.
Returns the first value for which the predicate
returns true.
find(predicate: (value?: T, key?: number, iter?: Iterable<number, T>) => boolean,
context?: any,
notSetValue?: T): T
Iterable#find()
Returns the last value for which the predicate
returns true.
findLast(predicate: (value?: T, key?: number, iter?: Iterable<number, T>) => boolean,
context?: any,
notSetValue?: T): T
Iterable#findLast()
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, key?: number, iter?: Iterable<number, T>) => boolean,
context?: any,
notSetValue?: T): Array<any>
Iterable#findEntry()
Returns the last [key, value] entry for which the predicate
returns true.
findLastEntry(predicate: (value?: T, key?: number, iter?: Iterable<number, T>) => boolean,
context?: any,
notSetValue?: T): Array<any>
Iterable#findLastEntry()
Note: predicate
will be called for each entry in reverse.
Returns the key for which the predicate
returns true.
findKey(predicate: (value?: T,
key?: number,
iter?: Iterable.Keyed<number, T>) => boolean,
context?: any): number
Iterable#findKey()
Returns the last key for which the predicate
returns true.
findLastKey(predicate: (value?: T,
key?: number,
iter?: Iterable.Keyed<number, T>) => boolean,
context?: any): number
Iterable#findLastKey()
Note: predicate
will be called for each entry in reverse.
Returns the key associated with the search value, or undefined.
keyOf(searchValue: T): number
Iterable#keyOf()
Returns the last key associated with the search value, or undefined.
lastKeyOf(searchValue: T): number
Iterable#lastKeyOf()
Returns the maximum value in this collection. If any values are comparatively equivalent, the first one found will be returned.
max(comparator?: (valueA: T, valueB: T) => number): T
Iterable#max()
The comparator
is used in the same way as Iterable#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?: Iterable<number, T>) => C,
comparator?: (valueA: C, valueB: C) => number): T
Iterable#maxBy()
hitters.maxBy(hitter => hitter.avgHits);
Returns the minimum value in this collection. If any values are comparatively equivalent, the first one found will be returned.
min(comparator?: (valueA: T, valueB: T) => number): T
Iterable#min()
The comparator
is used in the same way as Iterable#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?: Iterable<number, T>) => C,
comparator?: (valueA: C, valueB: C) => number): T
Iterable#minBy()
hitters.minBy(hitter => hitter.avgHits);
Returns the first index at which a given value can be found in the Iterable, or -1 if it is not present.
indexOf(searchValue: T): number
Iterable.Indexed#indexOf()
Returns the last index at which a given value can be found in the Iterable, or -1 if it is not present.
lastIndexOf(searchValue: T): number
Iterable.Indexed#lastIndexOf()
Returns the first index in the Iterable where a value satisfies the provided predicate function. Otherwise -1 is returned.
findIndex(predicate: (value?: T, index?: number, iter?: Iterable.Indexed<T>) => boolean,
context?: any): number
Iterable.Indexed#findIndex()
Returns the last index in the Iterable where a value satisfies the provided predicate function. Otherwise -1 is returned.
findLastIndex(predicate: (value?: T, index?: number, iter?: Iterable.Indexed<T>) => boolean,
context?: any): number
Iterable.Indexed#findLastIndex()
isSubset(iter: Iterable<any, T>): boolean
isSubset(iter: Array<T>): boolean
Iterable#isSubset()
isSuperset(iter: Iterable<any, T>): boolean
isSuperset(iter: Array<T>): boolean
Iterable#isSuperset()