-
Notifications
You must be signed in to change notification settings - Fork 1
flatMap
Subhajit Sahu edited this page Feb 3, 2021
·
19 revisions
Flatten nested iterable, based on map function.
function flatMap(x, fm, ft)
// x: a nested iterable
// fm: map function (v, i, x)
// ft: flatten test (v, i, x) [isList]
const xiterable = require('extra-iterable');
var x = [[1, 2], [3, [4, [5]]]];
[...xiterable.flatMap(x)];
// → [1, 2, 3, [4, [5]]]
[...xiterable.flatMap(x, v => xiterable.flat(v, 1))];
// → [1, 2, 3, 4, [5]]
[...xiterable.flatMap(x, v => xiterable.flat(v))];
// → [1, 2, 3, 4, 5]