-
Notifications
You must be signed in to change notification settings - Fork 1
flatMap
Subhajit Sahu edited this page Jun 17, 2020
·
17 revisions
Flattens nested set, using map function. 🏃 📼 📦 🌔 📒
set.flatMap(x, [fn]);
// x: a nested set
// fn: map function (v, v, x)
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 }