Hyperlinkv0.8.0-beta.28

HashMap

HashMap.findFirstconsteffect/HashMap.ts:1189
<K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (
  self: HashMap<K, A>
) => Option<[K, A]>
<K, A>(self: HashMap<K, A>, predicate: (a: A, k: K) => boolean): Option<
  [K, A]
>

Returns the first element that satisfies the specified predicate, or None if no such element exists.

Example (Finding the first matching entry)

import { HashMap, Option } from "effect"

const map = HashMap.make(["a", 1], ["b", 2], ["c", 3])
const result = HashMap.findFirst(map, (value, key) => key === "b" && value > 1)
console.log(result) // Option.some(["b", 2])
console.log(Option.getOrElse(result, () => ["", 0])) // ["b", 2]
elements
export const findFirst: {
  <K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (self: HashMap<K, A>) => Option<[K, A]>
  <K, A>(self: HashMap<K, A>, predicate: (a: A, k: K) => boolean): Option<[K, A]>
} = internal.findFirst
Referenced by 1 symbols