/** * @since 2.0.0 */ import type * as Chunk from "./Chunk.js" import type * as HashSet from "./HashSet.js" import * as internal from "./internal/stm/tSet.js" import type * as Option from "./Option.js" import type { Predicate } from "./Predicate.js" import type * as STM from "./STM.js" import type * as TMap from "./TMap.js" import type * as Types from "./Types.js" /** * @since 2.0.0 * @category symbols */ export const TSetTypeId: unique symbol = internal.TSetTypeId /** * @since 2.0.0 * @category symbols */ export type TSetTypeId = typeof TSetTypeId /** * Transactional set implemented on top of `TMap`. * * @since 2.0.0 * @category models */ export interface TSet extends TSet.Variance {} /** * @internal * @since 2.0.0 */ export interface TSet { /** @internal */ readonly tMap: TMap.TMap } /** * @since 2.0.0 */ export declare namespace TSet { /** * @since 2.0.0 * @category models */ export interface Variance { readonly [TSetTypeId]: { readonly _A: Types.Invariant } } } /** * Stores new element in the set. * * @since 2.0.0 * @category mutations */ export const add: { /** * Stores new element in the set. * * @since 2.0.0 * @category mutations */ (value: A): (self: TSet) => STM.STM /** * Stores new element in the set. * * @since 2.0.0 * @category mutations */ (self: TSet, value: A): STM.STM } = internal.add /** * Atomically transforms the set into the difference of itself and the * provided set. * * @since 2.0.0 * @category mutations */ export const difference: { /** * Atomically transforms the set into the difference of itself and the * provided set. * * @since 2.0.0 * @category mutations */ (other: TSet): (self: TSet) => STM.STM /** * Atomically transforms the set into the difference of itself and the * provided set. * * @since 2.0.0 * @category mutations */ (self: TSet, other: TSet): STM.STM } = internal.difference /** * Makes an empty `TSet`. * * @since 2.0.0 * @category constructors */ export const empty: () => STM.STM> = internal.empty /** * Atomically performs transactional-effect for each element in set. * * @since 2.0.0 * @category elements */ export const forEach: { /** * Atomically performs transactional-effect for each element in set. * * @since 2.0.0 * @category elements */ (f: (value: A) => STM.STM): (self: TSet) => STM.STM /** * Atomically performs transactional-effect for each element in set. * * @since 2.0.0 * @category elements */ (self: TSet, f: (value: A) => STM.STM): STM.STM } = internal.forEach /** * Creates a new `TSet` from an iterable collection of values. * * @since 2.0.0 * @category constructors */ export const fromIterable: (iterable: Iterable) => STM.STM> = internal.fromIterable /** * Tests whether or not set contains an element. * * @since 2.0.0 * @category elements */ export const has: { /** * Tests whether or not set contains an element. * * @since 2.0.0 * @category elements */ (value: A): (self: TSet) => STM.STM /** * Tests whether or not set contains an element. * * @since 2.0.0 * @category elements */ (self: TSet, value: A): STM.STM } = internal.has /** * Atomically transforms the set into the intersection of itself and the * provided set. * * @since 2.0.0 * @category mutations */ export const intersection: { /** * Atomically transforms the set into the intersection of itself and the * provided set. * * @since 2.0.0 * @category mutations */ (other: TSet): (self: TSet) => STM.STM /** * Atomically transforms the set into the intersection of itself and the * provided set. * * @since 2.0.0 * @category mutations */ (self: TSet, other: TSet): STM.STM } = internal.intersection /** * Tests if the set is empty or not * * @since 2.0.0 * @category getters */ export const isEmpty: (self: TSet) => STM.STM = internal.isEmpty /** * Makes a new `TSet` that is initialized with specified values. * * @since 2.0.0 * @category constructors */ export const make: >( ...elements: Elements ) => STM.STM> = internal.make /** * Atomically folds using a pure function. * * @since 2.0.0 * @category folding */ export const reduce: { /** * Atomically folds using a pure function. * * @since 2.0.0 * @category folding */ (zero: Z, f: (accumulator: Z, value: A) => Z): (self: TSet) => STM.STM /** * Atomically folds using a pure function. * * @since 2.0.0 * @category folding */ (self: TSet, zero: Z, f: (accumulator: Z, value: A) => Z): STM.STM } = internal.reduce /** * Atomically folds using a transactional function. * * @since 2.0.0 * @category folding */ export const reduceSTM: { /** * Atomically folds using a transactional function. * * @since 2.0.0 * @category folding */ (zero: Z, f: (accumulator: Z, value: A) => STM.STM): (self: TSet) => STM.STM /** * Atomically folds using a transactional function. * * @since 2.0.0 * @category folding */ (self: TSet, zero: Z, f: (accumulator: Z, value: A) => STM.STM): STM.STM } = internal.reduceSTM /** * Removes a single element from the set. * * @since 2.0.0 * @category mutations */ export const remove: { /** * Removes a single element from the set. * * @since 2.0.0 * @category mutations */ (value: A): (self: TSet) => STM.STM /** * Removes a single element from the set. * * @since 2.0.0 * @category mutations */ (self: TSet, value: A): STM.STM } = internal.remove /** * Removes elements from the set. * * @since 2.0.0 * @category mutations */ export const removeAll: { /** * Removes elements from the set. * * @since 2.0.0 * @category mutations */ (iterable: Iterable): (self: TSet) => STM.STM /** * Removes elements from the set. * * @since 2.0.0 * @category mutations */ (self: TSet, iterable: Iterable): STM.STM } = internal.removeAll /** * Removes entries from a `TSet` that satisfy the specified predicate and returns the removed entries * (or `void` if `discard = true`). * * @since 2.0.0 * @category mutations */ export const removeIf: { /** * Removes entries from a `TSet` that satisfy the specified predicate and returns the removed entries * (or `void` if `discard = true`). * * @since 2.0.0 * @category mutations */ ( predicate: Predicate, options: { readonly discard: true } ): (self: TSet) => STM.STM /** * Removes entries from a `TSet` that satisfy the specified predicate and returns the removed entries * (or `void` if `discard = true`). * * @since 2.0.0 * @category mutations */ ( predicate: Predicate, options?: { readonly discard: false } ): (self: TSet) => STM.STM> /** * Removes entries from a `TSet` that satisfy the specified predicate and returns the removed entries * (or `void` if `discard = true`). * * @since 2.0.0 * @category mutations */ ( self: TSet, predicate: Predicate, options: { readonly discard: true } ): STM.STM /** * Removes entries from a `TSet` that satisfy the specified predicate and returns the removed entries * (or `void` if `discard = true`). * * @since 2.0.0 * @category mutations */ ( self: TSet, predicate: Predicate, options?: { readonly discard: false } ): STM.STM> } = internal.removeIf /** * Retains entries in a `TSet` that satisfy the specified predicate and returns the removed entries * (or `void` if `discard = true`). * * @since 2.0.0 * @category mutations */ export const retainIf: { /** * Retains entries in a `TSet` that satisfy the specified predicate and returns the removed entries * (or `void` if `discard = true`). * * @since 2.0.0 * @category mutations */ ( predicate: Predicate, options: { readonly discard: true } ): (self: TSet) => STM.STM /** * Retains entries in a `TSet` that satisfy the specified predicate and returns the removed entries * (or `void` if `discard = true`). * * @since 2.0.0 * @category mutations */ ( predicate: Predicate, options?: { readonly discard: false } ): (self: TSet) => STM.STM> /** * Retains entries in a `TSet` that satisfy the specified predicate and returns the removed entries * (or `void` if `discard = true`). * * @since 2.0.0 * @category mutations */ ( self: TSet, predicate: Predicate, options: { readonly discard: true } ): STM.STM /** * Retains entries in a `TSet` that satisfy the specified predicate and returns the removed entries * (or `void` if `discard = true`). * * @since 2.0.0 * @category mutations */ ( self: TSet, predicate: Predicate, options?: { readonly discard: false } ): STM.STM> } = internal.retainIf /** * Returns the set's cardinality. * * @since 2.0.0 * @category getters */ export const size: (self: TSet) => STM.STM = internal.size /** * Takes the first matching value, or retries until there is one. * * @since 2.0.0 * @category mutations */ export const takeFirst: { /** * Takes the first matching value, or retries until there is one. * * @since 2.0.0 * @category mutations */ (pf: (a: A) => Option.Option): (self: TSet) => STM.STM /** * Takes the first matching value, or retries until there is one. * * @since 2.0.0 * @category mutations */ (self: TSet, pf: (a: A) => Option.Option): STM.STM } = internal.takeFirst /** * Takes the first matching value, or retries until there is one. * * @since 2.0.0 * @category mutations */ export const takeFirstSTM: { /** * Takes the first matching value, or retries until there is one. * * @since 2.0.0 * @category mutations */ (pf: (a: A) => STM.STM, R>): (self: TSet) => STM.STM /** * Takes the first matching value, or retries until there is one. * * @since 2.0.0 * @category mutations */ (self: TSet, pf: (a: A) => STM.STM, R>): STM.STM } = internal.takeFirstSTM /** * Takes all matching values, or retries until there is at least one. * * @since 2.0.0 * @category mutations */ export const takeSome: { /** * Takes all matching values, or retries until there is at least one. * * @since 2.0.0 * @category mutations */ (pf: (a: A) => Option.Option): (self: TSet) => STM.STM<[B, ...Array]> /** * Takes all matching values, or retries until there is at least one. * * @since 2.0.0 * @category mutations */ (self: TSet, pf: (a: A) => Option.Option): STM.STM<[B, ...Array]> } = internal.takeSome /** * Takes all matching values, or retries until there is at least one. * * @since 2.0.0 * @category mutations */ export const takeSomeSTM: { /** * Takes all matching values, or retries until there is at least one. * * @since 2.0.0 * @category mutations */ (pf: (a: A) => STM.STM, R>): (self: TSet) => STM.STM<[B, ...Array], E, R> /** * Takes all matching values, or retries until there is at least one. * * @since 2.0.0 * @category mutations */ (self: TSet, pf: (a: A) => STM.STM, R>): STM.STM<[B, ...Array], E, R> } = internal.takeSomeSTM /** * Collects all elements into a `Chunk`. * * @since 2.0.0 * @category destructors */ export const toChunk: (self: TSet) => STM.STM> = internal.toChunk /** * Collects all elements into a `HashSet`. * * @since 2.0.0 * @category destructors */ export const toHashSet: (self: TSet) => STM.STM> = internal.toHashSet /** * Collects all elements into a `Array`. * * @since 2.0.0 * @category destructors */ export const toArray: (self: TSet) => STM.STM> = internal.toArray /** * Collects all elements into a `ReadonlySet`. * * @since 2.0.0 * @category destructors */ export const toReadonlySet: (self: TSet) => STM.STM> = internal.toReadonlySet /** * Atomically updates all elements using a pure function. * * @since 2.0.0 * @category mutations */ export const transform: { /** * Atomically updates all elements using a pure function. * * @since 2.0.0 * @category mutations */ (f: (a: A) => A): (self: TSet) => STM.STM /** * Atomically updates all elements using a pure function. * * @since 2.0.0 * @category mutations */ (self: TSet, f: (a: A) => A): STM.STM } = internal.transform /** * Atomically updates all elements using a transactional function. * * @since 2.0.0 * @category mutations */ export const transformSTM: { /** * Atomically updates all elements using a transactional function. * * @since 2.0.0 * @category mutations */ (f: (a: A) => STM.STM): (self: TSet) => STM.STM /** * Atomically updates all elements using a transactional function. * * @since 2.0.0 * @category mutations */ (self: TSet, f: (a: A) => STM.STM): STM.STM } = internal.transformSTM /** * Atomically transforms the set into the union of itself and the provided * set. * * @since 2.0.0 * @category mutations */ export const union: { /** * Atomically transforms the set into the union of itself and the provided * set. * * @since 2.0.0 * @category mutations */ (other: TSet): (self: TSet) => STM.STM /** * Atomically transforms the set into the union of itself and the provided * set. * * @since 2.0.0 * @category mutations */ (self: TSet, other: TSet): STM.STM } = internal.union