September 2017
Intermediate to advanced
216 pages
6h 8m
English
The simplest way to empty a collection is to replace it with a new instance, as shown here:
const empty = (collection) => { if (collection instanceof List) { return List(); } if (collection instanceof Map) { return Map(); } return null;};const myList = List.of(1, 2);const myMap = Map.of('one', 1, 'two', 2);const myEmptyList = empty(myList);const myEmptyMap = empty(myMap);console.log('myList', myList.toJS());// -> myList [ 1, 2 ]console.log('myEmptyList', myEmptyList.toJS());// -> myEmptyList []console.log('myMap', myMap.toJS());// -> myMap { one: 1, two: 2 }console.log('myEmptyMap', myEmptyMap.toJS());// -> myEmptyMap {}
We've created a little helper function called empty(). The idea is that it accepts ...
Read now
Unlock full access