Skip to content

HashSet

Stores unique values in an immutable hash set.

A HashSet<A> contains at most one value for each equality class according to Effect's Equal and Hash rules. Membership checks, additions, removals, and set operations return new sets. This module also includes constructors, union, intersection, difference, subset checks, mapping, filtering, and reducing helpers.

20 exports Added in v2.0.0 Source

Combinators

difference

Added in v2.0.0 Source

Creates the difference of two HashSets (elements in the first set that are not in the second).

Signature

declare const difference: {
  <V1>(that: HashSet<V1>): <V0>(self: HashSet<V0>) => HashSet<V0>;
  <V0, V1>(self: HashSet<V0>, that: HashSet<V1>): HashSet<V0>;
};

intersection

Added in v2.0.0 Source

Creates the intersection of two HashSets.

Signature

declare const intersection: {
  <V1>(that: HashSet<V1>): <V0>(self: HashSet<V0>) => HashSet<V1 & V0>;
  <V0, V1>(self: HashSet<V0>, that: HashSet<V1>): HashSet<V0 & V1>;
};

union

Added in v2.0.0 Source

Creates the union of two HashSets.

Signature

declare const union: {
  <V1>(that: HashSet<V1>): <V0>(self: HashSet<V0>) => HashSet<V1 | V0>;
  <V0, V1>(self: HashSet<V0>, that: HashSet<V1>): HashSet<V0 | V1>;
};

Constructors

empty

Added in v2.0.0 Source

Creates an empty HashSet.

Signature

declare const empty: <V = never>() => HashSet<V>;

fromIterable

Added in v2.0.0 Source

Creates a HashSet from an iterable collection of values.

Signature

declare const fromIterable: <V>(values: Iterable<V>) => HashSet<V>;

make

Added in v2.0.0 Source

Creates a HashSet from a variable number of values.

Signature

declare const make: <Values extends ReadonlyArray<any>>(
  ...values: Values
) => HashSet<Values[number]>;

Filtering

filter

Added in v2.0.0 Source

Filters the HashSet keeping only values that satisfy the predicate.

Signature

declare const filter: {
  <V, U>(refinement: Refinement<NoInfer<V>, U>): (self: HashSet<V>) => HashSet<U>;
  <V>(predicate: Predicate<NoInfer<V>>): (self: HashSet<V>) => HashSet<V>;
  <V, U>(self: HashSet<V>, refinement: Refinement<V, U>): HashSet<U>;
  <V>(self: HashSet<V>, predicate: Predicate<V>): HashSet<V>;
};

Folding

reduce

Added in v2.0.0 Source

Reduces the HashSet 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: HashSet<V>) => U;
  <V, U>(self: HashSet<V>, zero: U, f: (accumulator: U, value: V) => U): U;
};

Getters

size

Added in v2.0.0 Source

Returns the number of values in the HashSet.

Signature

declare const size: <V>(self: HashSet<V>) => number;

Guards

isHashSet

Added in v2.0.0 Source

Checks whether a value is a HashSet.

Signature

declare const isHashSet: {
  <V>(u: Iterable<V>): u is HashSet<V>;
  (u: unknown): u is HashSet<unknown>;
};

Mapping

map

Added in v2.0.0 Source

Maps each value in the HashSet using the provided function.

Signature

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

Models

HashSet interface

Added in v2.0.0 Source

A HashSet is an immutable set data structure that provides efficient storage and retrieval of unique values. It uses a HashMap internally for optimal performance.

Signature

interface HashSet<out Value> extends Iterable<Value>, Equal, Pipeable, Inspectable {
  readonly "~effect/collections/HashSet": "~effect/collections/HashSet";
}

Mutations

add

Added in v2.0.0 Source

Adds a value to the HashSet, returning a new HashSet.

Signature

declare const add: {
  <V>(value: V): (self: HashSet<V>) => HashSet<V>;
  <V>(self: HashSet<V>, value: V): HashSet<V>;
};

remove

Added in v2.0.0 Source

Removes a value from the HashSet, returning a new HashSet.

Signature

declare const remove: {
  <V>(value: V): (self: HashSet<V>) => HashSet<V>;
  <V>(self: HashSet<V>, value: V): HashSet<V>;
};

Other

HashSet

Added in v2.0.0 Source

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

Predicates

every

Added in v2.0.0 Source

Checks whether all values in the HashSet satisfy the predicate.

Signature

declare const every: {
  <V>(predicate: Predicate<V>): (self: HashSet<V>) => boolean;
  <V>(self: HashSet<V>, predicate: Predicate<V>): boolean;
};

has

Added in v2.0.0 Source

Checks whether the HashSet contains the specified value.

Signature

declare const has: {
  <V>(value: V): (self: HashSet<V>) => boolean;
  <V>(self: HashSet<V>, value: V): boolean;
};

isEmpty

Added in v4.0.0 Source

Checks whether the HashSet is empty.

Signature

declare const isEmpty: <V>(self: HashSet<V>) => boolean;

isSubset

Added in v2.0.0 Source

Checks whether a HashSet is a subset of another HashSet.

Signature

declare const isSubset: {
  <V1>(that: HashSet<V1>): <V0>(self: HashSet<V0>) => boolean;
  <V0, V1>(self: HashSet<V0>, that: HashSet<V1>): boolean;
};

some

Added in v2.0.0 Source

Checks whether at least one value in the HashSet satisfies the predicate.

Signature

declare const some: {
  <V>(predicate: Predicate<V>): (self: HashSet<V>) => boolean;
  <V>(self: HashSet<V>, predicate: Predicate<V>): boolean;
};