getOr
ts
function Map.getOr<K, V, U>(
target: ReadonlyMap<K, V>,
key: NoInfer<K>,
or: U,
): Exclude<V, null | undefined> | UGets the value associated with the specified key, or returns the fallback value if the value is null or undefined.
Example
ts
import { Map } from "@monstermann/map";
Map.getOr(
new Map([
["a", 1],
["b", null],
]),
"a",
0,
); // 1
Map.getOr(
new Map([
["a", 1],
["b", null],
]),
"b",
0,
); // 0
Map.getOr(
new Map([
["a", 1],
["b", null],
]),
"c",
0,
); // 0ts
import { Map } from "@monstermann/map";
pipe(
new Map([
["a", 1],
["b", null],
]),
Map.getOr("a", 0),
); // 1
pipe(
new Map([
["a", 1],
["b", null],
]),
Map.getOr("b", 0),
); // 0
pipe(
new Map([
["a", 1],
["b", null],
]),
Map.getOr("c", 0),
); // 0