Hyperlinkv0.8.0-beta.28

TxHashSet

TxHashSet.hasconsteffect/TxHashSet.ts:417
<V>(value: V): (self: TxHashSet<V>) => Effect.Effect<boolean>
<V>(self: TxHashSet<V>, value: V): Effect.Effect<boolean>

Checks whether the TxHashSet contains the specified value.

Example (Checking membership)

import { Effect, Equal, Hash, TxHashSet } from "effect"

const program = Effect.gen(function*() {
  const txSet = yield* TxHashSet.make("apple", "banana", "cherry")

  console.log(yield* TxHashSet.has(txSet, "apple")) // true
  console.log(yield* TxHashSet.has(txSet, "grape")) // false

  // Works with any type that implements Equal
  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 = yield* TxHashSet.make(new Person("Alice"), new Person("Bob"))
  console.log(yield* TxHashSet.has(people, new Person("Alice"))) // true
})
elements
export const has: {
  <V>(value: V): (self: TxHashSet<V>) => Effect.Effect<boolean>
  <V>(self: TxHashSet<V>, value: V): Effect.Effect<boolean>
} = dual<
  <V>(value: V) => (self: TxHashSet<V>) => Effect.Effect<boolean>,
  <V>(self: TxHashSet<V>, value: V) => Effect.Effect<boolean>
>(2, <V>(self: TxHashSet<V>, value: V) =>
  Effect.gen(function*() {
    const set = yield* TxRef.get(self.ref)
    return HashSet.has(set, value)
  }))