Skip to content

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.

23 exports Added in v2.0.0 Source

Combinators

difference

Added in v2.0.0 Source

Creates the difference of two TxHashSets (elements in the first set that are not in the second), returning a new TxHashSet.

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

Added in v2.0.0 Source

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>>;
};

union

Added in v2.0.0 Source

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

empty

Added in v2.0.0 Source

Creates an empty TxHashSet.

Signature

declare function empty<V = never>(): Effect<TxHashSet<V>>;

fromHashSet

Added in v4.0.0 Source

Creates a TxHashSet from an existing HashSet.

Signature

declare function fromHashSet<V>(hashSet: HashSet<V>): Effect<TxHashSet<V>>;

fromIterable

Added in v2.0.0 Source

Creates a TxHashSet from an iterable collection of values.

Signature

declare function fromIterable<V>(values: Iterable<V>): Effect<TxHashSet<V>>;

make

Added in v2.0.0 Source

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

toHashSet

Added in v2.0.0 Source

Converts the TxHashSet to an immutable HashSet snapshot.

Signature

declare function toHashSet<V>(self: TxHashSet<V>): Effect<HashSet<V>>;

Filtering

filter

Added in v4.0.0 Source

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

reduce

Added in v2.0.0 Source

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

size

Added in v2.0.0 Source

Returns the number of values in the TxHashSet.

Signature

declare function size<V>(self: TxHashSet<V>): Effect<number>;

Guards

isTxHashSet

Added in v4.0.0 Source

Checks whether a value is a TxHashSet.

Signature

declare function isTxHashSet(u: unknown): u is TxHashSet<unknown>;

Mapping

map

Added in v4.0.0 Source

Maps each value in the TxHashSet using the provided function, returning a new TxHashSet.

Signature

declare const map: {
  <V, U>(f: (value: V) => U): (self: TxHashSet<V>) => Effect<TxHashSet<U>>;
  <V, U>(self: TxHashSet<V>, f: (value: V) => U): Effect<TxHashSet<U>>;
};

Models

TxHashSet interface

Added in v4.0.0 Source

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

add

Added in v2.0.0 Source

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>;
};

clear

Added in v4.0.0 Source

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>;

remove

Added in v2.0.0 Source

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

TxHashSet

Added in v4.0.0 Source

The TxHashSet namespace contains type-level utilities and helper types for working with TxHashSet instances.

Predicates

every

Added in v4.0.0 Source

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>;
};

has

Added in v2.0.0 Source

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>;
};

isEmpty

Added in v2.0.0 Source

Checks whether the TxHashSet is empty.

Signature

declare function isEmpty<V>(self: TxHashSet<V>): Effect<boolean>;

isSubset

Added in v4.0.0 Source

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>;
};

some

Added in v4.0.0 Source

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>;
};