Skip to content

removePath$

Subhajit Sahu edited this page Dec 5, 2022 · 10 revisions

Remove value at path in a nested map.

Similar: hasPath, getPath, setPath$, removePath$.
Similar: get, set, remove.


function removePath$(x, p)
// x: a nested map (updated)
// p: path
const map = require('extra-map');

var x = new Map([['a', 2], ['b', 4], ['c', 6]]);
var y = new Map([['x', x], ['e', 10], ['f', 12]]);
map.removePath$(y, ['e']);
// → Map(2) { 'x' => Map(3) { 'a' => 2, 'b' => 4, 'c' => 6 }, 'f' => 12 }

y;
// → Map(2) { 'x' => Map(3) { 'a' => 2, 'b' => 4, 'c' => 6 }, 'f' => 12 }

map.removePath$(y, ['x', 'b']);
// → Map(2) { 'x' => Map(2) { 'a' => 2, 'c' => 6 }, 'f' => 12 }

map.removePath$(y, ['x', 'b', 'c']);
// → Map(2) { 'x' => Map(2) { 'a' => 2, 'c' => 6 }, 'f' => 12 } (no effect)


References