<V>(self: TxHashSet<V>): Effect.Effect<void>Removes all values from the TxHashSet.
Details
This function mutates the original TxHashSet by clearing all values. It does not return a new TxHashSet reference.
Example (Clearing all values)
import { Effect, TxHashSet } from "effect"
const program = Effect.gen(function*() {
const txSet = yield* TxHashSet.make("a", "b", "c")
console.log(yield* TxHashSet.size(txSet)) // 3
yield* TxHashSet.clear(txSet)
console.log(yield* TxHashSet.size(txSet)) // 0
console.log(yield* TxHashSet.isEmpty(txSet)) // true
})export const const clear: <V>(
self: TxHashSet<V>
) => Effect.Effect<void>
Removes all values from the TxHashSet.
Details
This function mutates the original TxHashSet by clearing all values. It does not return a new TxHashSet reference.
Example (Clearing all values)
import { Effect, TxHashSet } from "effect"
const program = Effect.gen(function*() {
const txSet = yield* TxHashSet.make("a", "b", "c")
console.log(yield* TxHashSet.size(txSet)) // 3
yield* TxHashSet.clear(txSet)
console.log(yield* TxHashSet.size(txSet)) // 0
console.log(yield* TxHashSet.isEmpty(txSet)) // true
})
clear = <function (type parameter) V in <V>(self: TxHashSet<V>): Effect.Effect<void>V>(self: TxHashSet<V>(parameter) self: {
ref: TxRef.TxRef<HashSet.HashSet<V>>;
toString: () => string;
toJSON: () => unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface TxHashSet<in out V>A TxHashSet is a transactional hash set data structure that provides atomic operations on unique values within Effect transactions. It uses an immutable HashSet internally with TxRef for transactional semantics, ensuring all operations are performed atomically.
Details
Mutation operations such as add, remove, and clear update the original TxHashSet and return Effect<void> or Effect<boolean>. Transform operations such as union, intersection, difference, map, and filter create new TxHashSet instances and leave the original TxHashSet unchanged.
Example (Using transactional hash sets)
import { Effect, TxHashSet } from "effect"
const program = Effect.gen(function*() {
// Create a transactional hash set
const txSet = yield* TxHashSet.make("apple", "banana", "cherry")
// Single operations are automatically transactional
yield* TxHashSet.add(txSet, "grape")
const hasApple = yield* TxHashSet.has(txSet, "apple")
console.log(hasApple) // true
// Multi-step atomic operations
yield* Effect.tx(
Effect.gen(function*() {
const hasCherry = yield* TxHashSet.has(txSet, "cherry")
if (hasCherry) {
yield* TxHashSet.remove(txSet, "cherry")
yield* TxHashSet.add(txSet, "orange")
}
})
)
const size = yield* TxHashSet.size(txSet)
console.log(size) // 4
})
The TxHashSet namespace contains type-level utilities and helper types
for working with TxHashSet instances.
Example (Extracting value types inside transactions)
import { Effect, TxHashSet } from "effect"
const program = Effect.gen(function*() {
// Create a transactional color set
const colors = yield* TxHashSet.make("red", "green", "blue")
// Extract the value type for reuse
type Color = TxHashSet.TxHashSet.Value<typeof colors> // string
// Use extracted type in functions
const addColor = (color: Color) => TxHashSet.add(colors, color)
yield* addColor("yellow")
})
TxHashSet<function (type parameter) V in <V>(self: TxHashSet<V>): Effect.Effect<void>V>): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<void> => import TxRefTxRef.const set: {
<A>(value: A): (
self: TxRef<A>
) => Effect.Effect<void>
<A>(
self: TxRef<A>,
value: A
): Effect.Effect<void>
}
set(self: TxHashSet<V>(parameter) self: {
ref: TxRef.TxRef<HashSet.HashSet<V>>;
toString: () => string;
toJSON: () => unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self.TxHashSet<V>.ref: TxRef.TxRef<HashSet.HashSet<V>>(property) TxHashSet<V>.ref: {
version: number;
pending: Map<unknown, () => void>;
value: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
ref, import HashSetHashSet.const empty: <V = never>() => HashSet<V>Creates an empty HashSet.
Example (Creating an empty HashSet)
import { HashSet } from "effect"
const set = HashSet.empty<string>()
console.log(HashSet.size(set)) // 0
console.log(HashSet.isEmpty(set)) // true
// Add some values
const withValues = HashSet.add(HashSet.add(set, "hello"), "world")
console.log(HashSet.size(withValues)) // 2
empty<function (type parameter) V in <V>(self: TxHashSet<V>): Effect.Effect<void>V>())