Lazy mapping
The mapping that we've done so far has been called directly on collections. Mapping operations can be done lazily as part of a sequence of transformations that feed into a side-effect. Being able to filter and map lazily is part of a pattern that you'll use frequently with Immutable.js.
Multiple map() calls
Let's revisit our earlier example where we transformed two map values into a single capitalized name string:
const capitalize = s => `${s.charAt(0).toUpperCase()}${s.slice(1)}`; const myList = List.of( Map.of('first', 'joe', 'last', 'brown', 'age', 45), Map.of('first', 'john', 'last', 'smith', 'age', 32), Map.of('first', 'mary', 'last', 'wise', 'age', 56) ); myList .toSeq() .map(v => v.update('first', capitalize)) .map(v => v.update('last', capitalize)) .map(v => [v.get('first'), v.get('last')].join(' ')) .forEach(v => console.log('name', v)); // -> name Joe Brown // -> name John Smith // -> name Mary Wise
In this version of the...