September 2017
Intermediate to advanced
216 pages
6h 8m
English
As an alternative to for...of loops, the forEach() method can be used by sequences to execute side-effects, as follows:
const myList = List.of(1, 2, 3);const myMap = Map.of( 'one', 1, 'two', 2, 'three', 3);myList .toSeq() .forEach(item => console.log('myList', item)); // -> myList 1 // -> myList 2 // -> myList 3myMap .toSeq() .forEach(item => console.log('myMap', item)); // -> myMap 1 // -> myMap 2 // -> myMap 3
Using this approach, we end up with the same result as using for...of loops to execute our side-effects. The toSeq() call isn't necessary in order to use forEach(); however, the advantage that it has over for...of loops is that it's a chainable method that can be attached to your sequence transformations. ...
Read now
Unlock full access