Hyperlinkv0.8.0-beta.28

HashSet

HashSet.hasconsteffect/HashSet.ts:265
<V>(value: V): (self: HashSet<V>) => boolean
<V>(self: HashSet<V>, value: V): boolean

Checks whether the HashSet contains the specified value.

Example (Checking HashSet membership)

import { Equal, Hash, HashSet } from "effect"

// Works with any type that implements Equal

const set = HashSet.make("apple", "banana", "cherry")

console.log(HashSet.has(set, "apple")) // true
console.log(HashSet.has(set, "grape")) // false

class Person implements Equal.Equal {
  constructor(readonly name: string) {}

  [Equal.symbol](other: unknown) {
    return other instanceof Person && this.name === other.name
  }

  [Hash.symbol](): number {
    return Hash.string(this.name)
  }
}

const people = HashSet.make(new Person("Alice"), new Person("Bob"))
console.log(HashSet.has(people, new Person("Alice"))) // true
elements
Source effect/HashSet.ts:2657 lines
export const has: {
  <V>(value: V): (self: HashSet<V>) => boolean
  <V>(self: HashSet<V>, value: V): boolean
} = Dual.dual<
  <V>(value: V) => (self: HashSet<V>) => boolean,
  <V>(self: HashSet<V>, value: V) => boolean
>(2, internal.has)
Referenced by 2 symbols