September 2017
Intermediate to advanced
216 pages
6h 8m
English
Immutable.js collections follow the JavaScript iterable protocol. Any object that follows it can be used in a for...of loop. This includes sequences, as shown here:
const myList = List.of(1, 2, 3);const myMap = Map.of( 'one', 1, 'two', 2, 'three', 3);for (let item of myList.toSeq()) { console.log('myList', item); // -> myList 1 // -> myList 2 // -> myList 3}for (let item of myMap.toSeq()) { console.log('myMap', item); // -> myMap [ 'one', 1 ] // -> myMap [ 'two', 2 ] // -> myMap [ 'three', 3 ]}
Here, we're converting myList and myMap into their respective sequence types using toSeq(). Then, we're iterating over each value inside of a for...of loop. This is a side-effect: we're iterating over a sequence in order ...
Read now
Unlock full access