Iterators!
All Sequences, including both concrete collections (Map, Vector, Set) and lazy Sequences (mapped, filtered) can be iterated.
API:
values()
returns an iterator object where each call to next()
provides the next value.
keys()
returns an iterator object where each call to next()
provides the next key.
entries()
returns an iterator object where each call to next()
provides the next entry as a [key, value] tuple.
Example:
var myMap = Immutable.Map([['A', 1], ['B', 2], ['C', 3]]);
var entries = myMap.entries();
entries.next() // { value: ['A', 1], done: false }
entries.next() // { value: ['B', 2], done: false }
entries.next() // { value: ['C', 3], done: false }
entries.next() // { value: undefined, done: true }
All Sequences also support iteration via the @@iterator
and Symbol.iterator
methods, so they can be used in ES6 for-of comprehensions.
New
interpose()
- Sequence documentation is easier to follow now that methods are categorized and alphabetized.
- A number of lazy sequence optimizations. For example,
seq.flip().reverse().flip()
becomesseq.reverse()
. - Optimizations that allow
get()
andhas()
to be O(1) on lazy sequences.
Bugs
- Equality checking via
Immutable.is
orseq.equals()
could throw or incorrectly return false.