-
Notifications
You must be signed in to change notification settings - Fork 3
flatMap
Subhajit Sahu edited this page Dec 8, 2022
·
13 revisions
Flatten nested object, using map function.
function flatMap(x, fm, ft)
// x: a nested object
// fm: map function (v, k, x)
// ft: test function (v, k, x)
const object = require('extra-object');
var x = {ab: {a: 1, b: 2}, cde: {c: 3, de: {d: 4, e: {e: 5}}}};
object.flatMap(x);
// → { a: 1, b: 2, c: 3, de: { d: 4, e: { e: 5 } } }
object.flatMap(x, v => object.flat(v, 1));
// → { a: 1, b: 2, c: 3, d: 4, e: { e: 5 } }
object.flatMap(x, v => object.flat(v));
// → { a: 1, b: 2, c: 3, d: 4, e: 5 }