<Values extends ReadonlyArray<any>>(...values: Values): HashSet<
Values[number]
>Creates a HashSet from a variable number of values.
Example (Creating a HashSet from values)
import { HashSet } from "effect"
const fruits = HashSet.make("apple", "banana", "cherry")
console.log(HashSet.size(fruits)) // 3
const numbers = HashSet.make(1, 2, 3, 2, 1) // Duplicates ignored
console.log(HashSet.size(numbers)) // 3
const mixed = HashSet.make("hello", 42, true)
console.log(HashSet.size(mixed)) // 3constructors
Source effect/HashSet.ts:1493 lines
export const const make: <
Values extends ReadonlyArray<any>
>(
...values: Values
) => HashSet<Values[number]>
Creates a HashSet from a variable number of values.
Example (Creating a HashSet from values)
import { HashSet } from "effect"
const fruits = HashSet.make("apple", "banana", "cherry")
console.log(HashSet.size(fruits)) // 3
const numbers = HashSet.make(1, 2, 3, 2, 1) // Duplicates ignored
console.log(HashSet.size(numbers)) // 3
const mixed = HashSet.make("hello", 42, true)
console.log(HashSet.size(mixed)) // 3
make: <function (type parameter) Values in <Values extends ReadonlyArray<any>>(...values: Values): HashSet<Values[number]>Values extends interface ReadonlyArray<T>ReadonlyArray<any>>(
...values: Values extends ReadonlyArray<any>values: function (type parameter) Values in <Values extends ReadonlyArray<any>>(...values: Values): HashSet<Values[number]>Values
) => interface HashSet<out Value>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.
Example (Creating and updating a HashSet)
import { HashSet } from "effect"
// Create a HashSet
const set = HashSet.make("apple", "banana", "cherry")
// Check membership
console.log(HashSet.has(set, "apple")) // true
console.log(HashSet.has(set, "grape")) // false
// Add values (returns new HashSet)
const updated = HashSet.add(set, "grape")
console.log(HashSet.size(updated)) // 4
// Remove values (returns new HashSet)
const smaller = HashSet.remove(set, "banana")
console.log(HashSet.size(smaller)) // 2
The HashSet namespace contains type-level utilities and helper types
for working with HashSet instances.
Example (Extracting value types from a HashSet)
import { HashSet } from "effect"
// Create a concrete HashSet for type extraction
const fruits = HashSet.make("apple", "banana", "cherry")
// Extract the value type for reuse
type Fruit = HashSet.HashSet.Value<typeof fruits> // string
// Use extracted type in functions
const processFruit = (fruit: Fruit) => {
return `Processing ${fruit}`
}
HashSet<function (type parameter) Values in <Values extends ReadonlyArray<any>>(...values: Values): HashSet<Values[number]>Values[number]> = import internalinternal.const make: <
Values extends ReadonlyArray<any>
>(
...values: Values
) => internal.HashSet<Values[number]>
makeReferenced by 1 symbols