TxHashSet
Transactional hash sets for storing unique values inside Effect transactions.
A TxHashSet keeps an immutable HashSet inside a TxRef, so membership checks and updates can commit atomically with other transactional operations. Use it when several pieces of shared transactional state must change together, such as adding a value only after checking related state. The module includes the usual set operations, including adding, removing, membership checks, set algebra, mapping, filtering, reducing, and conversion back to HashSet.
Combinators
difference
Signature
declare const difference: {
<V1>(that: TxHashSet<V1>): <V0>(self: TxHashSet<V0>) => Effect<TxHashSet<V0>>;
<V0, V1>(self: TxHashSet<V0>, that: TxHashSet<V1>): Effect<TxHashSet<V0>>;
};intersection
Creates the intersection of two TxHashSets, returning a new TxHashSet.
Signature
declare const intersection: {
<V1>(that: TxHashSet<V1>): <V0>(self: TxHashSet<V0>) => Effect<TxHashSet<V1 & V0>>;
<V0, V1>(self: TxHashSet<V0>, that: TxHashSet<V1>): Effect<TxHashSet<V0 & V1>>;
};Creates the union of two TxHashSets, returning a new TxHashSet.
Signature
declare const union: {
<V1>(that: TxHashSet<V1>): <V0>(self: TxHashSet<V0>) => Effect<TxHashSet<V1 | V0>>;
<V0, V1>(self: TxHashSet<V0>, that: TxHashSet<V1>): Effect<TxHashSet<V0 | V1>>;
};Constructors
Creates an empty TxHashSet.
Signature
declare function empty<V = never>(): Effect<TxHashSet<V>>;fromHashSet
Creates a TxHashSet from an existing HashSet.
Signature
declare function fromHashSet<V>(hashSet: HashSet<V>): Effect<TxHashSet<V>>;fromIterable
Creates a TxHashSet from an iterable collection of values.
Signature
declare function fromIterable<V>(values: Iterable<V>): Effect<TxHashSet<V>>;Creates a TxHashSet from a variable number of values.
Signature
declare function make<Values extends readonly Array<any>>(...values: Values): Effect<TxHashSet<Values[number]>>Converting
Filtering
Filters the TxHashSet keeping only values that satisfy the predicate, returning a new TxHashSet.
Signature
declare const filter: {
<V, U>(refinement: Refinement<NoInfer<V>, U>): (self: TxHashSet<V>) => Effect<TxHashSet<U>>;
<V>(predicate: Predicate<NoInfer<V>>): (self: TxHashSet<V>) => Effect<TxHashSet<V>>;
<V, U>(self: TxHashSet<V>, refinement: Refinement<V, U>): Effect<TxHashSet<U>>;
<V>(self: TxHashSet<V>, predicate: Predicate<V>): Effect<TxHashSet<V>>;
};Folding
Reduces the TxHashSet to a single value by iterating through the values and applying an accumulator function.
Signature
declare const reduce: {
<V, U>(zero: U, f: (accumulator: U, value: V) => U): (self: TxHashSet<V>) => Effect<U>;
<V, U>(self: TxHashSet<V>, zero: U, f: (accumulator: U, value: V) => U): Effect<U>;
};Getters
Guards
isTxHashSet
Checks whether a value is a TxHashSet.
Signature
declare function isTxHashSet(u: unknown): u is TxHashSet<unknown>;Mapping
Models
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.
Signature
interface TxHashSet<in out V> extends Inspectable, Pipeable {
readonly "~effect/transactions/TxHashSet": "~effect/transactions/TxHashSet";
readonly ref: TxRef<HashSet<V>>;
}Mutations
Adds a value to the TxHashSet. If the value already exists, the operation has no effect.
Details
This function mutates the original TxHashSet by adding the specified value. It does not return a new TxHashSet reference.
Signature
declare const add: {
<V>(value: V): (self: TxHashSet<V>) => Effect<void>;
<V>(self: TxHashSet<V>, value: V): 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.
Signature
declare function clear<V>(self: TxHashSet<V>): Effect<void>;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.
Signature
declare const remove: {
<V>(value: V): (self: TxHashSet<V>) => Effect<boolean>;
<V>(self: TxHashSet<V>, value: V): Effect<boolean>;
};Other
Predicates
Checks whether all values in the TxHashSet satisfy the predicate.
Signature
declare const every: {
<V>(predicate: Predicate<V>): (self: TxHashSet<V>) => Effect<boolean>;
<V>(self: TxHashSet<V>, predicate: Predicate<V>): Effect<boolean>;
};Checks whether the TxHashSet contains the specified value.
Signature
declare const has: {
<V>(value: V): (self: TxHashSet<V>) => Effect<boolean>;
<V>(self: TxHashSet<V>, value: V): Effect<boolean>;
};Checks whether the TxHashSet is empty.
Signature
declare function isEmpty<V>(self: TxHashSet<V>): Effect<boolean>;Checks whether a TxHashSet is a subset of another TxHashSet.
Signature
declare const isSubset: {
<V1>(that: TxHashSet<V1>): <V0>(self: TxHashSet<V0>) => Effect<boolean>;
<V0, V1>(self: TxHashSet<V0>, that: TxHashSet<V1>): Effect<boolean>;
};Checks whether at least one value in the TxHashSet satisfies the predicate.
Signature
declare const some: {
<V>(predicate: Predicate<V>): (self: TxHashSet<V>) => Effect<boolean>;
<V>(self: TxHashSet<V>, predicate: Predicate<V>): Effect<boolean>;
};
Creates the difference of two TxHashSets (elements in the first set that are not in the second), returning a new TxHashSet.