-
Notifications
You must be signed in to change notification settings - Fork 1
flatMap
Subhajit Sahu edited this page Dec 2, 2022
·
17 revisions
Flatten nested set, based on map function.
function flatMap(x, fm, ft)
// x: a nested set
// fm: map function (v, v, x)
// ft: flatten test function (v, v, x) [is]
const set = require('extra-set');
var x = new Set([
new Set([1, 2]),
new Set([3, new Set([4, new Set([5])])])
]);
set.flatMap(x);
// → Set(4) { 1, 2, 3, Set(2) { 4, Set(1) { 5 } } }
set.flatMap(x, v => set.flat(v, 1));
// → Set(5) { 1, 2, 3, 4, Set(1) { 5 } }
set.flatMap(x, v => set.flat(v));
// → Set(5) { 1, 2, 3, 4, 5 }