-
Notifications
You must be signed in to change notification settings - Fork 1
flatMap
Subhajit Sahu edited this page Feb 3, 2021
·
19 revisions
Flattens nested iterable, based on map function. 🏃 📼 📦 🌔 📒
iterable.flatMap(x, [fm], [ft]);
// x: a nested iterable
// fm: map function (v, i, x)
// ft: test function (v, i, x)
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 ]