September 2017
Intermediate to advanced
216 pages
6h 8m
English
Sometimes, you don't want the default behavior of flatten(), which is to deep flatten collections. Instead, you want to shallow flatten the collection. For example, if you know the structure of the data with which you are dealing, you might not want to include deeply-nested collection values in the flattened result:
const myList = List.of( List.of('first', 'second'), List.of('third', 'fourth', List.of('fifth')), List.of('sixth', 'seventh'));const myFlattenedList = myList.flatten();const myShallowList = myList .flatten(true) .filterNot(List.isList);console.log('myList', myList.toJS());// -> myList [ [ 'first', 'second' ],// -> [ 'third', 'fourth', [ 'fifth' ] ],// -> [ 'sixth', 'seventh' ] ]console.log('myFlattenedList', ...Read now
Unlock full access