Skip to content

removeOr

ts
function Map.removeOr<K, V, U>(
    target: ReadonlyMap<K, V>,
    key: NoInfer<K>,
    or: U,
): Map<K, V> | U

Removes the specified key from the map, or returns the fallback value if the key doesn't exist.

Example

ts
import { Map } from "@monstermann/map";

Map.removeOr(
    new Map([
        ["a", 1],
        ["b", 2],
    ]),
    "a",
    null,
); // Map(1) { "b" => 2 }

Map.removeOr(
    new Map([
        ["a", 1],
        ["b", 2],
    ]),
    "c",
    null,
); // null
ts
import { Map } from "@monstermann/map";

pipe(
    new Map([
        ["a", 1],
        ["b", 2],
    ]),
    Map.removeOr("a", null),
); // Map(1) { "b" => 2 }

pipe(
    new Map([
        ["a", 1],
        ["b", 2],
    ]),
    Map.removeOr("c", null),
); // null