findReplace
ts
function Map.findReplace<K, V>(
target: ReadonlyMap<K, V>,
predicate: (
value: NoInfer<V>,
key: NoInfer<K>,
target: ReadonlyMap<K, V>,
) => boolean,
replacement: NoInfer<V>,
): ReadonlyMap<K, V>Finds the first entry in the map that satisfies the provided predicate function and replaces its value with replacement, returning a new map with the replaced value.
Example
ts
import { Map } from "@monstermann/map";
Map.findReplace(
new Map([
["a", 1],
["b", 2],
["c", 3],
]),
(value) => value > 1,
10,
); // Map(3) { "a" => 1, "b" => 10, "c" => 3 }ts
import { Map } from "@monstermann/map";
pipe(
new Map([
["a", 1],
["b", 2],
["c", 3],
]),
Map.findReplace((value) => value > 1, 10),
); // Map(3) { "a" => 1, "b" => 10, "c" => 3 }