Hyperlinkv0.8.0-beta.28

TxHashSet

TxHashSet.fromIterableconsteffect/TxHashSet.ts:238
<V>(values: Iterable<V>): Effect.Effect<TxHashSet<V>>

Creates a TxHashSet from an iterable collection of values.

Example (Creating a transactional hash set from an iterable)

import { Effect, TxHashSet } from "effect"

const program = Effect.gen(function*() {
  const fromArray = yield* TxHashSet.fromIterable(["a", "b", "c", "b", "a"])
  console.log(yield* TxHashSet.size(fromArray)) // 3

  const fromSet = yield* TxHashSet.fromIterable(new Set([1, 2, 3]))
  console.log(yield* TxHashSet.size(fromSet)) // 3

  const fromString = yield* TxHashSet.fromIterable("hello")
  const values = yield* TxHashSet.toHashSet(fromString)
  console.log(Array.from(values).sort()) // ["e", "h", "l", "o"]
})
constructors
export const fromIterable = <V>(values: Iterable<V>): Effect.Effect<TxHashSet<V>> =>
  Effect.gen(function*() {
    const hashSet = HashSet.fromIterable(values)
    const ref = yield* TxRef.make(hashSet)
    return makeTxHashSet(ref)
  })