Hyperlinkv0.8.0-beta.28

TxHashSet

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

Removes a value from the TxHashSet.

Details

This function mutates the original TxHashSet by removing the specified value. It does not return a new TxHashSet reference.

Example (Removing values)

import { Effect, TxHashSet } from "effect"

const program = Effect.gen(function*() {
  const txSet = yield* TxHashSet.make("a", "b", "c")

  const removed = yield* TxHashSet.remove(txSet, "b")
  console.log(removed) // true (value existed and was removed)
  console.log(yield* TxHashSet.size(txSet)) // 2
  console.log(yield* TxHashSet.has(txSet, "b")) // false

  // Removing non-existent value returns false
  const notRemoved = yield* TxHashSet.remove(txSet, "d")
  console.log(notRemoved) // false
})
mutations
export const remove: {
  <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 currentSet = yield* TxRef.get(self.ref)
    const existed = HashSet.has(currentSet, value)
    if (existed) {
      yield* TxRef.set(self.ref, HashSet.remove(currentSet, value))
    }
    return existed
  }).pipe(Effect.tx))