A type of Map that has the additional guarantee that the iteration order of entries will be the order in which they were set().
type OrderedMap<K, V> extends Map<K, V>The iteration behavior of OrderedMap is the same as native ES6 Map and JavaScript Object.
Note that OrderedMap are more expensive than non-ordered Map and may
consume more memory. OrderedMap#set is amortized O(log32 N), but not
stable.
OrderedMap<K, V>(): OrderedMap<K, V>
OrderedMap<K, V>(iter: Iterable.Keyed<K, V>): OrderedMap<K, V>
OrderedMap<K, V>(iter: Iterable<any, Array<any>>): OrderedMap<K, V>
OrderedMap<K, V>(array: Array<Array<any>>): OrderedMap<K, V>
OrderedMap<V>(obj: {[key: string]: V}): OrderedMap<string, V>
OrderedMap<K, V>(iterator: Iterator<Array<any>>): OrderedMap<K, V>
OrderedMap<K, V>(iterable: Object): OrderedMap<K, V>
OrderedMap.isOrderedMap(maybeOrderedMap: any): boolean
Returns a new Map which excludes this key.
delete(key: K): Map<K, V>
Map#delete()remove()Note: delete cannot be safely used in IE8, but is provided to mirror
the ES6 collection API.
update(updater: (value: Map<K, V>) => Map<K, V>): Map<K, V>
update(key: K, updater: (value: V) => V): Map<K, V>
update(key: K, notSetValue: V, updater: (value: V) => V): Map<K, V>
Map#update()merge(...iterables: Iterable<K, V>[]): Map<K, V>
merge(...iterables: {[key: string]: V}[]): Map<string, V>
Map#merge()mergeWith(merger: (previous?: V, next?: V, key?: K) => V,
...iterables: Iterable<K, V>[]): Map<K, V>
mergeWith(merger: (previous?: V, next?: V, key?: K) => V,
...iterables: {[key: string]: V}[]): Map<string, V>
Map#mergeWith()mergeDeep(...iterables: Iterable<K, V>[]): Map<K, V>
mergeDeep(...iterables: {[key: string]: V}[]): Map<string, V>
Map#mergeDeep()mergeDeepWith(merger: (previous?: V, next?: V, key?: K) => V,
...iterables: Iterable<K, V>[]): Map<K, V>
mergeDeepWith(merger: (previous?: V, next?: V, key?: K) => V,
...iterables: {[key: string]: V}[]): Map<string, V>
Map#mergeDeepWith()setIn(keyPath: Array<any>, value: any): Map<K, V>
setIn(KeyPath: Iterable<any, any>, value: any): Map<K, V>
Map#setIn()deleteIn(keyPath: Array<any>): Map<K, V>
deleteIn(keyPath: Iterable<any, any>): Map<K, V>
Map#deleteIn()mergeIn(keyPath: Iterable<any, any>, ...iterables: Iterable<K, V>[]): Map<K, V>
mergeIn(keyPath: Array<any>, ...iterables: Iterable<K, V>[]): Map<K, V>
mergeIn(keyPath: Array<any>, ...iterables: {[key: string]: V}[]): Map<string, V>
Map#mergeIn()mergeDeepIn(): Map<K, V>
mergeDeepIn(keyPath: Array<any>, ...iterables: Iterable<K, V>[]): Map<K, V>
mergeDeepIn(keyPath: Array<any>,
...iterables: {[key: string]: V}[]): Map<string, V>
Map#mergeDeepIn()Every time you call one of the above functions, a new immutable Map is created. If a pure function calls a number of these to produce a final return value, then a penalty on performance and memory has been paid by creating all of the intermediate immutable Maps.
withMutations(mutator: (mutable: Map<K, V>) => any): Map<K, V>
Map#withMutations()If you need to apply a series of mutations to produce a new immutable
Map, withMutations() creates a temporary mutable copy of the Map which
can apply mutations in a highly performant manner. In fact, this is
exactly how complex mutations like merge are done.
As an example, this results in the creation of 2, not 4, new Maps:
var map1 = Immutable.Map();
var map2 = map1.withMutations(map => {
map.set('a', 1).set('b', 2).set('c', 3);
});
assert(map1.size === 0);
assert(map2.size === 3);Note: Not all methods can be used on a mutable collection or within
withMutations! Only set and merge may be used mutatively.
Another way to avoid creation of intermediate Immutable maps is to create
a mutable copy of this collection. Mutable copies always return this,
and thus shouldn't be used for equality. Your function should never return
a mutable copy of a collection, only use it internally to create a new
collection. If possible, use withMutations as it provides an easier to
use API.
asMutable(): Map<K, V>
Map#asMutable()Note: if the collection is already mutable, asMutable returns itself.
Note: Not all methods can be used on a mutable collection or within
withMutations! Only set and merge may be used mutatively.
The yin to asMutable's yang. Because it applies to mutable collections,
this operation is mutable and returns itself. Once performed, the mutable
copy has become immutable and can be safely returned from a function.
asImmutable(): Map<K, V>
Map#asImmutable()Returns a Seq.Keyed from this Iterable where indices are treated as keys.
toKeyedSeq(): Seq.Keyed<K, V>
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<V>
Iterable#toIndexedSeq()Returns a Seq.Set of the values of this Iterable, discarding keys.
toSetSeq(): Seq.Set<V>
Iterable#toSetSeq()All collections maintain their current size as an integer.
size: numberCollection#sizeTrue if this and the other Iterable have value equality, as defined
by Immutable.is().
equals(other: Iterable<K, V>): 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 hashCodes,
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: K, notSetValue?: V): V
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: K): boolean
Iterable#has()True if a value exists within this Iterable, using Immutable.is to determine equality
includes(value: V): 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<V>
Iterable#toArray()Shallowly converts this Iterable to an Object.
toObject(): {[key: string]: V}
Iterable#toObject()Throws if keys are not strings.
Converts this Iterable to a Map, Throws if keys are not hashable.
toMap(): Map<K, V>
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<K, V>
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<V>
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<V>
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<V>
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<V>
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<K>
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<V>
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<K>
Iterable#keySeq()Returns an Seq.Indexed of the values of this Iterable, discarding keys.
valueSeq(): Seq.Indexed<V>
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?: V, key?: K, iter?: Iterable<K, V>) => M,
context?: any): Iterable<K, 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?: V, key?: K, iter?: Iterable<K, V>) => boolean,
context?: any): Iterable<K, V>
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?: V, key?: K, iter?: Iterable<K, V>) => boolean,
context?: any): Iterable<K, V>
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<K, V>
Iterable#reverse()Returns a new Iterable of the same type which includes the same entries,
stably sorted by using a comparator.
sort(comparator?: (valueA: V, valueB: V) => number): Iterable<K, V>
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 valueB1 (or any positive number) if valueA comes after valueBWhen 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?: V, key?: K, iter?: Iterable<K, V>) => C,
comparator?: (valueA: C, valueB: C) => number): Iterable<K, V>
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?: V, key?: K, iter?: Iterable<K, V>) => G,
context?: any): Seq.Keyed<G, Iterable<K, V>>
Iterable#groupBy()Note: This is always an eager operation.
The sideEffect is executed for every entry in the Iterable.
forEach(sideEffect: (value?: V, key?: K, iter?: Iterable<K, V>) => 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<K, V>
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<K, V>
Iterable#rest()Returns a new Iterable of the same type containing all entries except the last.
butLast(): Iterable<K, V>
Iterable#butLast()Returns a new Iterable of the same type which excludes the first amount
entries from this Iterable.
skip(amount: number): Iterable<K, V>
Iterable#skip()Returns a new Iterable of the same type which excludes the last amount
entries from this Iterable.
skipLast(amount: number): Iterable<K, V>
Iterable#skipLast()Returns a new Iterable of the same type which includes entries starting
from when predicate first returns false.
skipWhile(predicate: (value?: V, key?: K, iter?: Iterable<K, V>) => boolean,
context?: any): Iterable<K, V>
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?: V, key?: K, iter?: Iterable<K, V>) => boolean,
context?: any): Iterable<K, V>
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<K, V>
Iterable#take()Returns a new Iterable of the same type which includes the last amount
entries from this Iterable.
takeLast(amount: number): Iterable<K, V>
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?: V, key?: K, iter?: Iterable<K, V>) => boolean,
context?: any): Iterable<K, V>
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?: V, key?: K, iter?: Iterable<K, V>) => boolean,
context?: any): Iterable<K, V>
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<K, V>
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?: V, key?: K, iter?: Iterable<K, V>) => Iterable<MK, MV>,
context?: any): Iterable<MK, MV>
flatMap<MK, MV>(mapper: (value?: V, key?: K, iter?: Iterable<K, V>) => any,
context?: any): Iterable<MK, MV>
Iterable#flatMap()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?: V, key?: K, iter?: Iterable<K, V>) => 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?: V, key?: K, iter?: Iterable<K, V>) => 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?: V, key?: K, iter?: Iterable<K, V>) => boolean,
context?: any): boolean
Iterable#every()True if predicate returns true for any entry in the Iterable.
some(predicate: (value?: V, key?: K, iter?: Iterable<K, V>) => 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?: V, key?: K, iter?: Iterable<K, V>) => 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?: V, key?: K, iter?: Iterable<K, V>) => 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?: V, key?: K, iter?: Iterable<K, V>) => boolean,
context?: any,
notSetValue?: V): V
Iterable#find()Returns the last value for which the predicate returns true.
findLast(predicate: (value?: V, key?: K, iter?: Iterable<K, V>) => boolean,
context?: any,
notSetValue?: V): V
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?: V, key?: K, iter?: Iterable<K, V>) => boolean,
context?: any,
notSetValue?: V): Array<any>
Iterable#findEntry()Returns the last [key, value] entry for which the predicate
returns true.
findLastEntry(predicate: (value?: V, key?: K, iter?: Iterable<K, V>) => boolean,
context?: any,
notSetValue?: V): 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?: V, key?: K, iter?: Iterable.Keyed<K, V>) => boolean,
context?: any): K
Iterable#findKey()Returns the last key for which the predicate returns true.
findLastKey(predicate: (value?: V, key?: K, iter?: Iterable.Keyed<K, V>) => boolean,
context?: any): K
Iterable#findLastKey()Note: predicate will be called for each entry in reverse.
Returns the key associated with the search value, or undefined.
keyOf(searchValue: V): K
Iterable#keyOf()Returns the last key associated with the search value, or undefined.
lastKeyOf(searchValue: V): K
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: V, valueB: V) => number): V
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?: V, key?: K, iter?: Iterable<K, V>) => C,
comparator?: (valueA: C, valueB: C) => number): V
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: V, valueB: V) => number): V
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?: V, key?: K, iter?: Iterable<K, V>) => C,
comparator?: (valueA: C, valueB: C) => number): V
Iterable#minBy()hitters.minBy(hitter => hitter.avgHits);
isSubset(iter: Iterable<any, V>): boolean
isSubset(iter: Array<V>): boolean
Iterable#isSubset()isSuperset(iter: Iterable<any, V>): boolean
isSuperset(iter: Array<V>): boolean
Iterable#isSuperset()Returns a new Iterable.Keyed of the same type where the keys and values have been flipped.
flip(): Iterable.Keyed<V, K>
Iterable.Keyed#flip()Seq({ a: 'z', b: 'y' }).flip() // { z: 'a', y: 'b' }
Returns a new Iterable.Keyed of the same type with keys passed through
a mapper function.
mapKeys<M>(mapper: (key?: K, value?: V, iter?: Iterable.Keyed<K, V>) => M,
context?: any): Iterable.Keyed<M, V>
Iterable.Keyed#mapKeys()Seq({ a: 1, b: 2 })
.mapKeys(x => x.toUpperCase())
// Seq { A: 1, B: 2 }
Returns a new Iterable.Keyed of the same type with entries
([key, value] tuples) passed through a mapper function.
mapEntries<KM, VM>(mapper: (entry?: Array<any>,
index?: number,
iter?: Iterable.Keyed<K, V>) => Array<any>,
context?: any): Iterable.Keyed<KM, VM>
Iterable.Keyed#mapEntries()Seq({ a: 1, b: 2 })
.mapEntries(([k, v]) => [k.toUpperCase(), v * 2])
// Seq { A: 2, B: 4 }