-
Notifications
You must be signed in to change notification settings - Fork 1
flatMap
Subhajit Sahu edited this page May 10, 2020
·
19 revisions
Flattens nested iterable, based on map function. 🏃 [:vhs:] 📦 🌔
iterable.flatMap(x, [fn], [ths]);
// x: a nested iterable
// fn: map function (v, i, x)
// ths: this argument
const iterable = require('extra-iterable');
var x = [[1, 2], [3, [4, [5]]]];
[...iterable.flatMap(x)];
// [ 1, 2, 3, [ 4, [ 5 ] ] ]
[...iterable.flatMap(x, v => iterable.flat(v, 1))];
// [ 1, 2, 3, 4, [ 5 ] ]
[...iterable.flatMap(x, v => iterable.flat(v))];
// [ 1, 2, 3, 4, 5 ]