findOrThrow
ts
function Map.findOrThrow<K, V>(
target: ReadonlyMap<K, V>,
predicate: (
value: NoInfer<V>,
key: NoInfer<K>,
target: ReadonlyMap<K, V>,
) => boolean,
): VReturns the first value in the map that satisfies the provided predicate function, or throws an error if no value is found.
Example
ts
import { Map } from "@monstermann/map";
Map.findOrThrow(
new Map([
["a", 1],
["b", 2],
["c", 3],
]),
(value) => value > 2,
); // 3ts
import { Map } from "@monstermann/map";
pipe(
new Map([
["a", 1],
["b", 2],
["c", 3],
]),
Map.findOrThrow((value) => value > 2),
); // 3