(u: unknown): u is TxHashSet<unknown>Checks whether a value is a TxHashSet.
Example (Checking for a TxHashSet)
import { Effect, HashSet, TxHashSet } from "effect"
const program = Effect.gen(function*() {
const txSet = yield* TxHashSet.make(1, 2, 3)
const hashSet = HashSet.make(1, 2, 3)
const array = [1, 2, 3]
console.log(TxHashSet.isTxHashSet(txSet)) // true
console.log(TxHashSet.isTxHashSet(hashSet)) // false
console.log(TxHashSet.isTxHashSet(array)) // false
console.log(TxHashSet.isTxHashSet(null)) // false
})export const const isTxHashSet: (
u: unknown
) => u is TxHashSet<unknown>
Checks whether a value is a TxHashSet.
Example (Checking for a TxHashSet)
import { Effect, HashSet, TxHashSet } from "effect"
const program = Effect.gen(function*() {
const txSet = yield* TxHashSet.make(1, 2, 3)
const hashSet = HashSet.make(1, 2, 3)
const array = [1, 2, 3]
console.log(TxHashSet.isTxHashSet(txSet)) // true
console.log(TxHashSet.isTxHashSet(hashSet)) // false
console.log(TxHashSet.isTxHashSet(array)) // false
console.log(TxHashSet.isTxHashSet(null)) // false
})
isTxHashSet = (u: unknownu: unknown): u: unknownu is 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<unknown> => import hasPropertyhasProperty(u: unknownu, const TypeId: "~effect/transactions/TxHashSet"TypeId)