effect 3.14.2 → 3.14.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,254 @@
1
1
  /**
2
+ * # HashSet
3
+ *
4
+ * An immutable `HashSet` provides a collection of unique values with efficient
5
+ * lookup, insertion and removal. Once created, a `HashSet` cannot be modified;
6
+ * any operation that would alter the set instead returns a new `HashSet` with
7
+ * the changes. This immutability offers benefits like predictable state
8
+ * management and easier reasoning about your code.
9
+ *
10
+ * ## What Problem Does It Solve?
11
+ *
12
+ * `HashSet` solves the problem of maintaining an unsorted collection where each
13
+ * value appears exactly once, with fast operations for checking membership and
14
+ * adding/removing values.
15
+ *
16
+ * ## When to Use
17
+ *
18
+ * Use `HashSet` when you need:
19
+ *
20
+ * - A collection with no duplicate values
21
+ * - Efficient membership testing (**`O(1)`** average complexity)
22
+ * - Set operations like union, intersection, and difference
23
+ * - An immutable data structure that preserves functional programming patterns
24
+ *
25
+ * ## Advanced Features
26
+ *
27
+ * HashSet provides operations for:
28
+ *
29
+ * - Transforming sets with map and flatMap
30
+ * - Filtering elements with filter
31
+ * - Combining sets with union, intersection and difference
32
+ * - Performance optimizations via mutable operations in controlled contexts
33
+ *
34
+ * ## Performance Characteristics
35
+ *
36
+ * - **Lookup** operations ({@link module:HashSet.has}): **`O(1)`** average time
37
+ * complexity
38
+ * - **Insertion** operations ({@link module:HashSet.add}): **`O(1)`** average time
39
+ * complexity
40
+ * - **Removal** operations ({@link module:HashSet.remove}): **`O(1)`** average
41
+ * time complexity
42
+ * - **Set** operations ({@link module:HashSet.union},
43
+ * {@link module:HashSet.intersection}): **`O(n)`** where n is the size of the
44
+ * smaller set
45
+ * - **Iteration**: **`O(n)`** where n is the size of the set
46
+ *
47
+ * The HashSet data structure implements the following traits:
48
+ *
49
+ * - {@link Iterable}: allows iterating over the values in the set
50
+ * - {@link Equal}: allows comparing two sets for value-based equality
51
+ * - {@link Pipeable}: allows chaining operations with the pipe operator
52
+ * - {@link Inspectable}: allows inspecting the contents of the set
53
+ *
54
+ * ## Operations Reference
55
+ *
56
+ * | Category | Operation | Description | Complexity |
57
+ * | ------------ | ----------------------------------- | ------------------------------------------- | ---------- |
58
+ * | constructors | {@link module:HashSet.empty} | Creates an empty HashSet | O(1) |
59
+ * | constructors | {@link module:HashSet.fromIterable} | Creates a HashSet from an iterable | O(n) |
60
+ * | constructors | {@link module:HashSet.make} | Creates a HashSet from multiple values | O(n) |
61
+ * | | | | |
62
+ * | elements | {@link module:HashSet.has} | Checks if a value exists in the set | O(1) avg |
63
+ * | elements | {@link module:HashSet.some} | Checks if any element satisfies a predicate | O(n) |
64
+ * | elements | {@link module:HashSet.every} | Checks if all elements satisfy a predicate | O(n) |
65
+ * | elements | {@link module:HashSet.isSubset} | Checks if a set is a subset of another | O(n) |
66
+ * | | | | |
67
+ * | getters | {@link module:HashSet.values} | Gets an iterator of all values | O(1) |
68
+ * | getters | {@link module:HashSet.toValues} | Gets an array of all values | O(n) |
69
+ * | getters | {@link module:HashSet.size} | Gets the number of elements | O(1) |
70
+ * | | | | |
71
+ * | mutations | {@link module:HashSet.add} | Adds a value to the set | O(1) avg |
72
+ * | mutations | {@link module:HashSet.remove} | Removes a value from the set | O(1) avg |
73
+ * | mutations | {@link module:HashSet.toggle} | Toggles a value's presence | O(1) avg |
74
+ * | | | | |
75
+ * | operations | {@link module:HashSet.difference} | Computes set difference (A - B) | O(n) |
76
+ * | operations | {@link module:HashSet.intersection} | Computes set intersection (A ∩ B) | O(n) |
77
+ * | operations | {@link module:HashSet.union} | Computes set union (A ∪ B) | O(n) |
78
+ * | | | | |
79
+ * | mapping | {@link module:HashSet.map} | Transforms each element | O(n) |
80
+ * | | | | |
81
+ * | sequencing | {@link module:HashSet.flatMap} | Transforms and flattens elements | O(n) |
82
+ * | | | | |
83
+ * | traversing | {@link module:HashSet.forEach} | Applies a function to each element | O(n) |
84
+ * | | | | |
85
+ * | folding | {@link module:HashSet.reduce} | Reduces the set to a single value | O(n) |
86
+ * | | | | |
87
+ * | filtering | {@link module:HashSet.filter} | Keeps elements that satisfy a predicate | O(n) |
88
+ * | | | | |
89
+ * | partitioning | {@link module:HashSet.partition} | Splits into two sets by a predicate | O(n) |
90
+ *
91
+ * ## Notes
92
+ *
93
+ * ### Composability with the Effect Ecosystem:
94
+ *
95
+ * This `HashSet` is designed to work seamlessly within the Effect ecosystem. It
96
+ * implements the {@link Iterable}, {@link Equal}, {@link Pipeable}, and
97
+ * {@link Inspectable} traits from Effect. This ensures compatibility with other
98
+ * Effect data structures and functionalities. For example, you can easily use
99
+ * Effect's `pipe` method to chain operations on the `HashSet`.
100
+ *
101
+ * **Equality of Elements with Effect's {@link Equal `Equal`} Trait:**
102
+ *
103
+ * This `HashSet` relies on Effect's {@link Equal} trait to determine the
104
+ * uniqueness of elements within the set. The way equality is checked depends on
105
+ * the type of the elements:
106
+ *
107
+ * - **Primitive Values:** For primitive JavaScript values like strings, numbers,
108
+ * booleans, `null`, and `undefined`, equality is determined by their value
109
+ * (similar to the `===` operator).
110
+ * - **Objects and Custom Types:** For objects and other custom types, equality is
111
+ * determined by whether those types implement the {@link Equal} interface
112
+ * themselves. If an element type implements `Equal`, the `HashSet` will
113
+ * delegate to that implementation to perform the equality check. This allows
114
+ * you to define custom logic for determining when two instances of your
115
+ * objects should be considered equal based on their properties, rather than
116
+ * just their object identity.
117
+ *
118
+ * ```ts
119
+ * import { Equal, Hash, HashSet } from "effect"
120
+ *
121
+ * class Person implements Equal.Equal {
122
+ * constructor(
123
+ * readonly id: number, // Unique identifier
124
+ * readonly name: string,
125
+ * readonly age: number
126
+ * ) {}
127
+ *
128
+ * // Define equality based on id, name, and age
129
+ * [Equal.symbol](that: Equal.Equal): boolean {
130
+ * if (that instanceof Person) {
131
+ * return (
132
+ * Equal.equals(this.id, that.id) &&
133
+ * Equal.equals(this.name, that.name) &&
134
+ * Equal.equals(this.age, that.age)
135
+ * )
136
+ * }
137
+ * return false
138
+ * }
139
+ *
140
+ * // Generate a hash code based on the unique id
141
+ * [Hash.symbol](): number {
142
+ * return Hash.hash(this.id)
143
+ * }
144
+ * }
145
+ *
146
+ * // Creating a HashSet with objects that implement the Equal interface
147
+ * const set = HashSet.empty().pipe(
148
+ * HashSet.add(new Person(1, "Alice", 30)),
149
+ * HashSet.add(new Person(1, "Alice", 30))
150
+ * )
151
+ *
152
+ * // HashSet recognizes them as equal, so only one element is stored
153
+ * console.log(HashSet.size(set))
154
+ * // Output: 1
155
+ * ```
156
+ *
157
+ * **Simplifying Equality and Hashing with `Data` and `Schema`:**
158
+ *
159
+ * Effect's {@link Data} and {@link Schema `Schema.Data`} modules offer powerful
160
+ * ways to automatically handle the implementation of both the {@link Equal} and
161
+ * {@link Hash} traits for your custom data structures.
162
+ *
163
+ * - **`Data` Module:** By using constructors like `Data.struct`, `Data.tuple`,
164
+ * `Data.array`, or `Data.case` to define your data types, Effect
165
+ * automatically generates the necessary implementations for value-based
166
+ * equality and consistent hashing. This significantly reduces boilerplate and
167
+ * ensures correctness.
168
+ *
169
+ * ```ts
170
+ * import { HashSet, Data, Equal } from "effect"
171
+ * import assert from "node:assert/strict"
172
+ *
173
+ * // Data.* implements the `Equal` traits for us
174
+ * const person1 = Data.struct({ id: 1, name: "Alice", age: 30 })
175
+ * const person2 = Data.struct({ id: 1, name: "Alice", age: 30 })
176
+ *
177
+ * assert(Equal.equals(person1, person2))
178
+ *
179
+ * const set = HashSet.empty().pipe(
180
+ * HashSet.add(person1),
181
+ * HashSet.add(person2)
182
+ * )
183
+ *
184
+ * // HashSet recognizes them as equal, so only one element is stored
185
+ * console.log(HashSet.size(set)) // Output: 1
186
+ * ```
187
+ *
188
+ * - **`Schema` Module:** When defining data schemas using the {@link Schema}
189
+ * module, you can use `Schema.Data` to automatically include the `Equal` and
190
+ * `Hash` traits in the decoded objects. This is particularly important when
191
+ * working with `HashSet`. **For decoded objects to be correctly recognized as
192
+ * equal within a `HashSet`, ensure that the schema for those objects is
193
+ * defined using `Schema.Data`.**
194
+ *
195
+ * ```ts
196
+ * import { Equal, HashSet, Schema } from "effect"
197
+ * import assert from "node:assert/strict"
198
+ *
199
+ * // Schema.Data implements the `Equal` traits for us
200
+ * const PersonSchema = Schema.Data(
201
+ * Schema.Struct({
202
+ * id: Schema.Number,
203
+ * name: Schema.String,
204
+ * age: Schema.Number
205
+ * })
206
+ * )
207
+ *
208
+ * const Person = Schema.decode(PersonSchema)
209
+ *
210
+ * const person1 = Person({ id: 1, name: "Alice", age: 30 })
211
+ * const person2 = Person({ id: 1, name: "Alice", age: 30 })
212
+ *
213
+ * assert(Equal.equals(person1, person2)) // Output: true
214
+ *
215
+ * const set = HashSet.empty().pipe(
216
+ * HashSet.add(person1),
217
+ * HashSet.add(person2)
218
+ * )
219
+ *
220
+ * // HashSet thanks to Schema.Data implementation of the `Equal` trait, recognizes the two Person as equal, so only one element is stored
221
+ * console.log(HashSet.size(set)) // Output: 1
222
+ * ```
223
+ *
224
+ * ### Interoperability with the JavaScript Runtime:
225
+ *
226
+ * To interoperate with the regular JavaScript runtime, Effect's `HashSet`
227
+ * provides methods to access its elements in formats readily usable by
228
+ * JavaScript APIs: {@link values `HashSet.values`},
229
+ * {@link toValues `HashSet.toValues`}
230
+ *
231
+ * ```ts
232
+ * import { HashSet } from "effect"
233
+ *
234
+ * const hashSet: HashSet.HashSet<number> = HashSet.make(1, 2, 3)
235
+ *
236
+ * // Using HashSet.values to convert HashSet.HashSet<A> to IterableIterator<A>
237
+ * const iterable: IterableIterator<number> = HashSet.values(hashSet)
238
+ *
239
+ * console.log(...iterable) // Logs: 1 2 3
240
+ *
241
+ * // Using HashSet.toValues to convert HashSet.HashSet<A> to Array<A>
242
+ * const array: Array<number> = HashSet.toValues(hashSet)
243
+ *
244
+ * console.log(array) // Logs: [ 1, 2, 3 ]
245
+ * ```
246
+ *
247
+ * Be mindful of performance implications (both time and space complexity) when
248
+ * frequently converting between Effect's immutable HashSet and mutable
249
+ * JavaScript data structures, especially for large collections.
250
+ *
251
+ * @module HashSet
2
252
  * @since 2.0.0
3
253
  */
4
254
  import type { Equal } from "./Equal.js";
@@ -13,126 +263,577 @@ declare const TypeId: unique symbol;
13
263
  */
14
264
  export type TypeId = typeof TypeId;
15
265
  /**
266
+ * @memberof HashSet
16
267
  * @since 2.0.0
17
268
  * @category models
269
+ * @example
270
+ *
271
+ * ```ts
272
+ * // Syntax
273
+ * import { HashSet } from "effect"
274
+ *
275
+ * let numberSet: HashSet.HashSet<number>
276
+ * ```
277
+ *
278
+ * @interface
18
279
  */
19
280
  export interface HashSet<out A> extends Iterable<A>, Equal, Pipeable, Inspectable {
20
281
  readonly [TypeId]: TypeId;
21
282
  }
22
283
  /**
284
+ * @memberof HashSet
23
285
  * @since 2.0.0
24
286
  * @category refinements
25
287
  */
26
288
  export declare const isHashSet: {
27
289
  /**
28
- * @since 2.0.0
29
- * @category refinements
290
+ * Type guard function to determine if a given iterable is a `HashSet`.
291
+ *
292
+ * This overload preserves the type of the iterable's elements.
293
+ *
294
+ * @example
295
+ *
296
+ * ```ts
297
+ * import { HashSet } from "effect"
298
+ *
299
+ * const numberIterable: Iterable<1 | 2 | 3> = [1, 2, 3]
300
+ *
301
+ * if (
302
+ * // if passed an Iterable<A> the type guard that preserves the type parameter <A>
303
+ * HashSet.isHashSet(numberIterable)
304
+ * ) {
305
+ * const HashSet: HashSet.HashSet<1 | 2 | 3> = numberIterable
306
+ * }
307
+ * ```
308
+ *
309
+ * @param u - The iterable input to be checked.
310
+ * @returns A boolean indicating whether the provided iterable is a `HashSet`.
30
311
  */
31
312
  <A>(u: Iterable<A>): u is HashSet<A>;
32
313
  /**
33
- * @since 2.0.0
34
- * @category refinements
314
+ * Type guard function that checks if the provided value is a `HashSet` of
315
+ * unknown type.
316
+ *
317
+ * @example
318
+ *
319
+ * ```ts
320
+ * import { HashSet } from "effect"
321
+ * import assert from "node:assert/strict"
322
+ *
323
+ * // Check if a value is a HashSet
324
+ * const set = HashSet.make(1, 2, 3)
325
+ *
326
+ * assert.equal(HashSet.isHashSet(set), true) // true
327
+ * assert.equal(HashSet.isHashSet(HashSet.empty()), true)
328
+ *
329
+ * // Works with any type
330
+ * assert.equal(HashSet.isHashSet(null), false) // false
331
+ * assert.equal(HashSet.isHashSet({}), false) // false
332
+ * assert.equal(HashSet.isHashSet([1, 2, 3]), false) // false
333
+ * ```
334
+ *
335
+ * @param u - The value to check.
336
+ * @returns A boolean indicating whether the value is a `HashSet<unknown>`.
35
337
  */
36
338
  (u: unknown): u is HashSet<unknown>;
37
339
  };
38
340
  /**
39
341
  * Creates an empty `HashSet`.
40
342
  *
343
+ * Time complexity: **`O(1)`**
344
+ *
345
+ * @memberof HashSet
41
346
  * @since 2.0.0
42
347
  * @category constructors
348
+ * @example
349
+ *
350
+ * ```ts
351
+ * import { HashSet, pipe } from "effect"
352
+ *
353
+ * console.log(
354
+ * pipe(
355
+ * // Provide a type argument to create a HashSet of a specific type
356
+ * HashSet.empty<number>(),
357
+ * HashSet.add(1),
358
+ * HashSet.add(1), // Notice the duplicate
359
+ * HashSet.add(2),
360
+ * HashSet.toValues
361
+ * )
362
+ * ) // Output: [1, 2]
363
+ * ```
364
+ *
365
+ * @see Other `HashSet` constructors are {@link module:HashSet.make} {@link module:HashSet.fromIterable}
43
366
  */
44
367
  export declare const empty: <A = never>() => HashSet<A>;
45
368
  /**
46
369
  * Creates a new `HashSet` from an iterable collection of values.
47
370
  *
371
+ * Time complexity: **`O(n)`** where n is the number of elements in the iterable
372
+ *
373
+ * @memberof HashSet
48
374
  * @since 2.0.0
49
375
  * @category constructors
376
+ * @example
377
+ *
378
+ * ```ts
379
+ * // Creating a HashSet from an Array
380
+ * import { HashSet, pipe } from "effect"
381
+ *
382
+ * console.log(
383
+ * pipe(
384
+ * [1, 2, 3, 4, 5, 1, 2, 3], // Array<number> is an Iterable<number>; Note the duplicates.
385
+ * HashSet.fromIterable,
386
+ * HashSet.toValues
387
+ * )
388
+ * ) // Output: [1, 2, 3, 4, 5]
389
+ * ```
390
+ *
391
+ * @example
392
+ *
393
+ * ```ts
394
+ * // Creating a HashSet from a Set
395
+ * import { HashSet, pipe } from "effect"
396
+ *
397
+ * console.log(
398
+ * pipe(
399
+ * new Set(["apple", "banana", "orange", "apple"]), // Set<string> is an Iterable<string>
400
+ * HashSet.fromIterable,
401
+ * HashSet.toValues
402
+ * )
403
+ * ) // Output: ["apple", "banana", "orange"]
404
+ * ```
405
+ *
406
+ * @example
407
+ *
408
+ * ```ts
409
+ * // Creating a HashSet from a Generator
410
+ * import { HashSet } from "effect"
411
+ *
412
+ * // Generator functions return iterables
413
+ * function* fibonacci(n: number): Generator<number, void, unknown> {
414
+ * let [a, b] = [0, 1]
415
+ * for (let i = 0; i < n; i++) {
416
+ * yield a
417
+ * ;[a, b] = [b, a + b]
418
+ * }
419
+ * }
420
+ *
421
+ * // Create a HashSet from the first 10 Fibonacci numbers
422
+ * const fibonacciSet = HashSet.fromIterable(fibonacci(10))
423
+ *
424
+ * console.log(HashSet.toValues(fibonacciSet))
425
+ * // Outputs: [0, 1, 2, 3, 5, 8, 13, 21, 34] but in unsorted order
426
+ * ```
427
+ *
428
+ * @example
429
+ *
430
+ * ```ts
431
+ * // Creating a HashSet from another HashSet
432
+ * import { HashSet, pipe } from "effect"
433
+ *
434
+ * console.log(
435
+ * pipe(
436
+ * // since HashSet implements the Iterable interface, we can use it to create a new HashSet
437
+ * HashSet.make(1, 2, 3, 4),
438
+ * HashSet.fromIterable,
439
+ * HashSet.toValues // turns the HashSet back into an array
440
+ * )
441
+ * ) // Output: [1, 2, 3, 4]
442
+ * ```
443
+ *
444
+ * @example
445
+ *
446
+ * ```ts
447
+ * // Creating a HashSet from other Effect's data structures like Chunk
448
+ * import { Chunk, HashSet, pipe } from "effect"
449
+ *
450
+ * console.log(
451
+ * pipe(
452
+ * Chunk.make(1, 2, 3, 4), // Iterable<number>
453
+ * HashSet.fromIterable,
454
+ * HashSet.toValues // turns the HashSet back into an array
455
+ * )
456
+ * ) // Outputs: [1, 2, 3, 4]
457
+ * ```
458
+ *
459
+ * @see Other `HashSet` constructors are {@link module:HashSet.empty} {@link module:HashSet.make}
50
460
  */
51
461
  export declare const fromIterable: <A>(elements: Iterable<A>) => HashSet<A>;
52
462
  /**
53
463
  * Construct a new `HashSet` from a variable number of values.
54
464
  *
465
+ * Time complexity: **`O(n)`** where n is the number of elements
466
+ *
467
+ * @memberof HashSet
55
468
  * @since 2.0.0
56
469
  * @category constructors
470
+ * @example
471
+ *
472
+ * ```ts
473
+ * import { Equal, Hash, HashSet, pipe } from "effect"
474
+ * import assert from "node:assert/strict"
475
+ *
476
+ * class Character implements Equal.Equal {
477
+ * readonly name: string
478
+ * readonly trait: string
479
+ *
480
+ * constructor(name: string, trait: string) {
481
+ * this.name = name
482
+ * this.trait = trait
483
+ * }
484
+ *
485
+ * // Define equality based on name, and trait
486
+ * [Equal.symbol](that: Equal.Equal): boolean {
487
+ * if (that instanceof Character) {
488
+ * return (
489
+ * Equal.equals(this.name, that.name) &&
490
+ * Equal.equals(this.trait, that.trait)
491
+ * )
492
+ * }
493
+ * return false
494
+ * }
495
+ *
496
+ * // Generate a hash code based on the sum of the character's name and trait
497
+ * [Hash.symbol](): number {
498
+ * return Hash.hash(this.name + this.trait)
499
+ * }
500
+ *
501
+ * static readonly of = (name: string, trait: string): Character => {
502
+ * return new Character(name, trait)
503
+ * }
504
+ * }
505
+ *
506
+ * assert.strictEqual(
507
+ * Equal.equals(
508
+ * HashSet.make(
509
+ * Character.of("Alice", "Curious"),
510
+ * Character.of("Alice", "Curious"),
511
+ * Character.of("White Rabbit", "Always late"),
512
+ * Character.of("Mad Hatter", "Tea enthusiast")
513
+ * ),
514
+ * // Is the same as adding each character to an empty set
515
+ * pipe(
516
+ * HashSet.empty(),
517
+ * HashSet.add(Character.of("Alice", "Curious")),
518
+ * HashSet.add(Character.of("Alice", "Curious")), // Alice tried to attend twice!
519
+ * HashSet.add(Character.of("White Rabbit", "Always late")),
520
+ * HashSet.add(Character.of("Mad Hatter", "Tea enthusiast"))
521
+ * )
522
+ * ),
523
+ * true,
524
+ * "`HashSet.make` and `HashSet.empty() + HashSet.add()` should be equal"
525
+ * )
526
+ *
527
+ * assert.strictEqual(
528
+ * Equal.equals(
529
+ * HashSet.make(
530
+ * Character.of("Alice", "Curious"),
531
+ * Character.of("Alice", "Curious"),
532
+ * Character.of("White Rabbit", "Always late"),
533
+ * Character.of("Mad Hatter", "Tea enthusiast")
534
+ * ),
535
+ * HashSet.fromIterable([
536
+ * Character.of("Alice", "Curious"),
537
+ * Character.of("Alice", "Curious"),
538
+ * Character.of("White Rabbit", "Always late"),
539
+ * Character.of("Mad Hatter", "Tea enthusiast")
540
+ * ])
541
+ * ),
542
+ * true,
543
+ * "`HashSet.make` and `HashSet.fromIterable` should be equal"
544
+ * )
545
+ * ```
546
+ *
547
+ * @see Other `HashSet` constructors are {@link module:HashSet.fromIterable} {@link module:HashSet.empty}
57
548
  */
58
549
  export declare const make: <As extends ReadonlyArray<any>>(...elements: As) => HashSet<As[number]>;
59
550
  /**
60
551
  * Checks if the specified value exists in the `HashSet`.
61
552
  *
553
+ * Time complexity: **`O(1)`** average
554
+ *
555
+ * @memberof HashSet
62
556
  * @since 2.0.0
63
557
  * @category elements
558
+ * @example
559
+ *
560
+ * ```ts
561
+ * // Syntax
562
+ * import { HashSet, pipe } from "effect"
563
+ *
564
+ * // with `data-last`, a.k.a. `pipeable` API
565
+ * pipe(HashSet.make(0, 1, 2), HashSet.has(3)) // false
566
+ *
567
+ * // or piped with the pipe function
568
+ * HashSet.make(0, 1, 2).pipe(HashSet.has(3)) // false
569
+ *
570
+ * // or with `data-first` API
571
+ * HashSet.has(HashSet.make(0, 1, 2), 3) // false
572
+ * ```
573
+ *
574
+ * @returns A `boolean` signaling the presence of the value in the HashSet
575
+ * @see Other `HashSet` elements are {@link module:HashSet.some} {@link module:HashSet.every} {@link module:HashSet.isSubset}
64
576
  */
65
577
  export declare const has: {
66
578
  /**
67
- * Checks if the specified value exists in the `HashSet`.
579
+ * @example
68
580
  *
69
- * @since 2.0.0
70
- * @category elements
581
+ * ```ts
582
+ * // `data-last` a.k.a. `pipeable` API
583
+ * import * as assert from "node:assert/strict"
584
+ * import { HashSet, pipe } from "effect"
585
+ *
586
+ * const set = HashSet.make(0, 1, 2)
587
+ *
588
+ * assert.equal(pipe(set, HashSet.has(0)), true)
589
+ * assert.equal(pipe(set, HashSet.has(1)), true)
590
+ * assert.equal(pipe(set, HashSet.has(2)), true)
591
+ * assert.equal(pipe(set, HashSet.has(3)), false)
592
+ * ```
71
593
  */
72
594
  <A>(value: A): (self: HashSet<A>) => boolean;
73
595
  /**
74
- * Checks if the specified value exists in the `HashSet`.
596
+ * @example
597
+ *
598
+ * ```ts
599
+ * // `data-first` API
600
+ * import * as assert from "node:assert/strict"
601
+ * import { HashSet, pipe } from "effect"
75
602
  *
76
- * @since 2.0.0
77
- * @category elements
603
+ * const set = HashSet.make(0, 1, 2)
604
+ *
605
+ * assert.equal(HashSet.has(set, 0), true)
606
+ * assert.equal(HashSet.has(set, 1), true)
607
+ * assert.equal(HashSet.has(set, 2), true)
608
+ * assert.equal(HashSet.has(set, 3), false)
609
+ * ```
78
610
  */
79
611
  <A>(self: HashSet<A>, value: A): boolean;
80
612
  };
81
613
  /**
82
614
  * Check if a predicate holds true for some `HashSet` element.
83
615
  *
616
+ * Time complexity: **`O(n)`** where n is the number of elements in the set
617
+ *
618
+ * @memberof HashSet
84
619
  * @since 2.0.0
85
620
  * @category elements
621
+ * @example
622
+ *
623
+ * ```ts
624
+ * // Syntax
625
+ * import { HashSet, pipe } from "effect"
626
+ *
627
+ * const set: HashSet.HashSet<number> = HashSet.make(0, 1, 2)
628
+ *
629
+ * // with `data-last`, a.k.a. `pipeable` API
630
+ * pipe(
631
+ * set,
632
+ * HashSet.some((n) => n > 0)
633
+ * ) // true
634
+ *
635
+ * // or piped with the pipe function
636
+ * set.pipe(HashSet.some((n) => n > 0)) // true
637
+ *
638
+ * // or with `data-first` API
639
+ * HashSet.some(set, (n) => n > 0) // true
640
+ * ```
641
+ *
642
+ * @see Other `HashSet` elements are {@link module:HashSet.has} {@link module:HashSet.every} {@link module:HashSet.isSubset}
86
643
  */
87
644
  export declare const some: {
88
645
  /**
89
- * Check if a predicate holds true for some `HashSet` element.
646
+ * @example
647
+ *
648
+ * ```ts
649
+ * // `data-last` a.k.a. `pipeable` API
650
+ * import * as assert from "node:assert/strict"
651
+ * import { HashSet, pipe } from "effect"
652
+ *
653
+ * const set = HashSet.make(0, 1, 2)
654
+ *
655
+ * assert.equal(
656
+ * pipe(
657
+ * set,
658
+ * HashSet.some((n) => n > 0)
659
+ * ),
660
+ * true
661
+ * )
90
662
  *
91
- * @since 2.0.0
92
- * @category elements
663
+ * assert.equal(
664
+ * pipe(
665
+ * set,
666
+ * HashSet.some((n) => n > 2)
667
+ * ),
668
+ * false
669
+ * )
670
+ * ```
93
671
  */
94
672
  <A>(f: Predicate<A>): (self: HashSet<A>) => boolean;
95
673
  /**
96
- * Check if a predicate holds true for some `HashSet` element.
674
+ * @example
97
675
  *
98
- * @since 2.0.0
99
- * @category elements
676
+ * ```ts
677
+ * // `data-first` API
678
+ * import * as assert from "node:assert/strict"
679
+ * import { HashSet } from "effect"
680
+ *
681
+ * const set = HashSet.make(0, 1, 2)
682
+ *
683
+ * assert.equal(
684
+ * HashSet.some(set, (n) => n > 0),
685
+ * true
686
+ * )
687
+ *
688
+ * assert.equal(
689
+ * HashSet.some(set, (n) => n > 2),
690
+ * false
691
+ * )
692
+ * ```
100
693
  */
101
694
  <A>(self: HashSet<A>, f: Predicate<A>): boolean;
102
695
  };
103
696
  /**
104
697
  * Check if a predicate holds true for every `HashSet` element.
105
698
  *
699
+ * Time complexity is **`O(n)`** as it needs to traverse the whole HashSet
700
+ * collection
701
+ *
702
+ * @memberof HashSet
106
703
  * @since 2.0.0
107
704
  * @category elements
705
+ * @example
706
+ *
707
+ * ```ts
708
+ * // Syntax with Refinement
709
+ * import { HashSet, pipe, Predicate } from "effect"
710
+ *
711
+ * const numberOrString = HashSet.make(1, "1", "one", "uno")
712
+ *
713
+ * // with `data-last`, a.k.a. `pipeable` API and `Refinement`
714
+ * pipe(
715
+ * numberOrString, // HashSet.HashSet<number | string>
716
+ * HashSet.every(Predicate.isString)
717
+ * ) // HashSet.HashSet<string>
718
+ *
719
+ * // or piped with the pipe function and `Refinement`
720
+ * numberOrString // HashSet.HashSet<number | string>
721
+ * .pipe(HashSet.every(Predicate.isString)) // HashSet.HashSet<string>
722
+ *
723
+ * // or with `data-first` API and `Refinement`
724
+ * HashSet.every(
725
+ * numberOrString, // HashSet.HashSet<number | string>
726
+ * Predicate.isString
727
+ * ) // HashSet.HashSet<string>
728
+ * ```
729
+ *
730
+ * @example
731
+ *
732
+ * ```ts
733
+ * // Syntax with Predicate
734
+ * import { HashSet, pipe } from "effect"
735
+ *
736
+ * const set = HashSet.make(1, 2, 3)
737
+ *
738
+ * // with `data-last`, a.k.a. `pipeable` API
739
+ * pipe(
740
+ * set,
741
+ * HashSet.every((n) => n >= 0)
742
+ * ) // true
743
+ *
744
+ * // or piped with the pipe function
745
+ * set.pipe(HashSet.every((n) => n >= 0)) // true
746
+ *
747
+ * // or with `data-first` API
748
+ * HashSet.every(set, (n) => n >= 0) // true
749
+ * ```
750
+ *
751
+ * @returns A boolean once it has evaluated that whole collection fulfill the
752
+ * Predicate function
753
+ * @see Other `HashSet` elements are {@link module:HashSet.has} {@link module:HashSet.some} {@link module:HashSet.isSubset}
108
754
  */
109
755
  export declare const every: {
110
756
  /**
111
- * Check if a predicate holds true for every `HashSet` element.
757
+ * @example
758
+ *
759
+ * ```ts
760
+ * import * as assert from "node:assert/strict"
761
+ * import { Effect, HashSet, pipe, Predicate } from "effect"
112
762
  *
113
- * @since 2.0.0
114
- * @category elements
763
+ * const numberOrString: HashSet.HashSet<number | string> = HashSet.make(
764
+ * 1,
765
+ * "1",
766
+ * "one",
767
+ * "uno"
768
+ * )
769
+ *
770
+ * assert.equal(
771
+ * pipe(
772
+ * numberOrString, // HashSet.HashSet<number | string>
773
+ * HashSet.every(Predicate.isString)
774
+ * ), // HashSet.HashSet<string>
775
+ * false
776
+ * )
777
+ * ```
115
778
  */
116
779
  <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: HashSet<A>) => self is HashSet<B>;
117
780
  /**
118
- * Check if a predicate holds true for every `HashSet` element.
781
+ * @example
782
+ *
783
+ * ```ts
784
+ * import * as assert from "node:assert/strict"
785
+ * import { HashSet, pipe } from "effect"
786
+ *
787
+ * const set = HashSet.make(0, 1, 2)
119
788
  *
120
- * @since 2.0.0
121
- * @category elements
789
+ * assert.equal(
790
+ * pipe(
791
+ * set,
792
+ * HashSet.every((n) => n >= 0)
793
+ * ),
794
+ * true
795
+ * )
796
+ * ```
122
797
  */
123
798
  <A>(predicate: Predicate<A>): (self: HashSet<A>) => boolean;
124
799
  /**
125
- * Check if a predicate holds true for every `HashSet` element.
800
+ * @example
126
801
  *
127
- * @since 2.0.0
128
- * @category elements
802
+ * ```ts
803
+ * import * as assert from "node:assert/strict"
804
+ * import { Effect, HashSet, pipe, Predicate } from "effect"
805
+ *
806
+ * const numberOrString: HashSet.HashSet<number | string> = HashSet.make(
807
+ * 1,
808
+ * "1",
809
+ * "one",
810
+ * "uno"
811
+ * )
812
+ *
813
+ * assert.equal(
814
+ * HashSet.every(
815
+ * numberOrString, // HashSet.HashSet<number | string>
816
+ * Predicate.isString
817
+ * ), // HashSet.HashSet<string>
818
+ * false
819
+ * )
820
+ * ```
129
821
  */
130
822
  <A, B extends A>(self: HashSet<A>, refinement: Refinement<A, B>): self is HashSet<B>;
131
823
  /**
132
- * Check if a predicate holds true for every `HashSet` element.
824
+ * @example
825
+ *
826
+ * ```ts
827
+ * import * as assert from "node:assert/strict"
828
+ * import { HashSet } from "effect"
133
829
  *
134
- * @since 2.0.0
135
- * @category elements
830
+ * const set = HashSet.make(0, 1, 2)
831
+ *
832
+ * assert.equal(
833
+ * HashSet.every(set, (n) => n >= 0),
834
+ * true
835
+ * )
836
+ * ```
136
837
  */
137
838
  <A>(self: HashSet<A>, predicate: Predicate<A>): boolean;
138
839
  };
@@ -142,211 +843,784 @@ export declare const every: {
142
843
  *
143
844
  * **NOTE**: the hash and equal of both sets must be the same.
144
845
  *
846
+ * Time complexity analysis is of **`O(n)`**
847
+ *
848
+ * @memberof HashSet
145
849
  * @since 2.0.0
146
850
  * @category elements
851
+ * @example
852
+ *
853
+ * ```ts
854
+ * // Syntax
855
+ * import { HashSet, pipe } from "effect"
856
+ *
857
+ * const set1 = HashSet.make(0, 1)
858
+ * const set2 = HashSet.make(1, 2)
859
+ * const set3 = HashSet.make(0, 1, 2)
860
+ *
861
+ * // with `data-last`, a.k.a. `pipeable` API
862
+ * pipe(set1, HashSet.isSubset(set2)) // false
863
+ * pipe(set1, HashSet.isSubset(set3)) // true
864
+ *
865
+ * // or piped with the pipe function
866
+ * set1.pipe(HashSet.isSubset(set2)) // false
867
+ * set1.pipe(HashSet.isSubset(set3)) // true
868
+ *
869
+ * // or with `data-first` API
870
+ * HashSet.isSubset(set1, set2) // false
871
+ * HashSet.isSubset(set1, set3) // true)
872
+ * ```
873
+ *
874
+ * @see Other `HashSet` elements are {@link module:HashSet.has} {@link module:HashSet.some} {@link module:HashSet.every}
147
875
  */
148
876
  export declare const isSubset: {
149
877
  /**
150
- * Returns `true` if and only if every element in the this `HashSet` is an
151
- * element of the second set,
878
+ * @example
879
+ *
880
+ * ```ts
881
+ * import { HashSet, pipe } from "effect"
882
+ * import * as assert from "node:assert/strict"
152
883
  *
153
- * **NOTE**: the hash and equal of both sets must be the same.
884
+ * assert.equal(
885
+ * pipe(
886
+ * HashSet.make(0, 1), //
887
+ * HashSet.isSubset(HashSet.make(1, 2))
888
+ * ),
889
+ * false
890
+ * )
154
891
  *
155
- * @since 2.0.0
156
- * @category elements
892
+ * assert.equal(
893
+ * pipe(
894
+ * HashSet.make(0, 1), //
895
+ * HashSet.isSubset(HashSet.make(0, 1, 2))
896
+ * ),
897
+ * true
898
+ * )
899
+ * ```
157
900
  */
158
901
  <A>(that: HashSet<A>): (self: HashSet<A>) => boolean;
159
902
  /**
160
- * Returns `true` if and only if every element in the this `HashSet` is an
161
- * element of the second set,
903
+ * @example
162
904
  *
163
- * **NOTE**: the hash and equal of both sets must be the same.
905
+ * ```ts
906
+ * import { HashSet } from "effect"
907
+ * import * as assert from "node:assert/strict"
164
908
  *
165
- * @since 2.0.0
166
- * @category elements
909
+ * assert.equal(HashSet.isSubset(set1, set2), false)
910
+ *
911
+ * assert.equal(HashSet.isSubset(set1, set3), true)
912
+ * ```
167
913
  */
168
914
  <A>(self: HashSet<A>, that: HashSet<A>): boolean;
169
915
  };
170
916
  /**
171
917
  * Returns an `IterableIterator` of the values in the `HashSet`.
172
918
  *
919
+ * Time complexity: **`O(1)`**
920
+ *
921
+ * @memberof HashSet
173
922
  * @since 2.0.0
174
923
  * @category getters
924
+ * @example
925
+ *
926
+ * ```ts
927
+ * import { HashSet, pipe } from "effect"
928
+ *
929
+ * const numberIterable = pipe(
930
+ * HashSet.make(0, 1, 1, 2), // HashSet.HashSet<number>
931
+ * HashSet.values // takes an HashSet<A> and returns an IterableIterator<A>
932
+ * )
933
+ *
934
+ * for (const number of numberIterable) {
935
+ * console.log(number) // it will logs: 0, 1, 2
936
+ * }
937
+ * ```
938
+ *
939
+ * @see Other `HashSet` getters are {@link module:HashSet.toValues} {@link module:HashSet.size}
175
940
  */
176
941
  export declare const values: <A>(self: HashSet<A>) => IterableIterator<A>;
177
942
  /**
178
943
  * Returns an `Array` of the values within the `HashSet`.
179
944
  *
945
+ * Time complexity: **`O(n)`** where n is the number of elements in the set
946
+ *
947
+ * @memberof HashSet
180
948
  * @since 3.13.0
181
949
  * @category getters
950
+ * @example
951
+ *
952
+ * ```ts
953
+ * import { HashSet, pipe } from "effect"
954
+ * import { deepStrictEqual } from "node:assert/strict"
955
+ *
956
+ * deepStrictEqual(
957
+ * pipe(
958
+ * HashSet.make(0, 1, 1, 2), // HashSet<number>
959
+ * HashSet.toValues // takes an HashSet<A> and returns an Array<A>
960
+ * ),
961
+ * Array.of(0, 1, 2)
962
+ * )
963
+ * ```
964
+ *
965
+ * @see Other `HashSet` getters are {@link module:HashSet.values} {@link module:HashSet.size}
182
966
  */
183
967
  export declare const toValues: <A>(self: HashSet<A>) => Array<A>;
184
968
  /**
185
969
  * Calculates the number of values in the `HashSet`.
186
970
  *
971
+ * Time complexity: **`O(1)`**
972
+ *
973
+ * @memberof HashSet
187
974
  * @since 2.0.0
188
975
  * @category getters
976
+ * @example
977
+ *
978
+ * ```ts
979
+ * import { HashSet, pipe } from "effect"
980
+ * import assert from "node:assert/strict"
981
+ *
982
+ * assert.deepStrictEqual(pipe(HashSet.empty(), HashSet.size), 0)
983
+ *
984
+ * assert.deepStrictEqual(
985
+ * pipe(HashSet.make(1, 2, 2, 3, 4, 3), HashSet.size),
986
+ * 4
987
+ * )
988
+ * ```
989
+ *
990
+ * @see Other `HashSet` getters are {@link module:HashSet.values} {@link module:HashSet.toValues}
189
991
  */
190
992
  export declare const size: <A>(self: HashSet<A>) => number;
191
993
  /**
192
- * Marks the `HashSet` as mutable.
994
+ * Creates a new mutable version of the `HashSet`
995
+ *
996
+ * When a `HashSet` is mutable, operations like {@link add} and {@link remove}
997
+ * modify the data structure in place instead of creating a new one, which is
998
+ * more efficient when performing multiple operations.
193
999
  *
1000
+ * @memberof HashSet
194
1001
  * @since 2.0.0
1002
+ * @example
1003
+ *
1004
+ * ```ts
1005
+ * import { HashSet } from "effect"
1006
+ * import assert from "node:assert/strict"
1007
+ *
1008
+ * const UPPER_BOUND = 10_000
1009
+ *
1010
+ * const immutableSet = HashSet.empty<number>().pipe(HashSet.add(0))
1011
+ *
1012
+ * // Create a mutable version of the immutableSet
1013
+ * const mutableSet = HashSet.beginMutation(immutableSet)
1014
+ *
1015
+ * for (let i = 1; i < UPPER_BOUND; i++) {
1016
+ * // Operations now modify the set in place instead of creating new instances
1017
+ * // This is more efficient when making multiple changes
1018
+ * const pointerToMutableSet = HashSet.add(mutableSet, i)
1019
+ *
1020
+ * // the two sets have the same identity, hence `add` is mutating mutableSet and not returning a new HashSet instance
1021
+ * assert(Object.is(mutableSet, pointerToMutableSet))
1022
+ * assert.equal(HashSet.has(mutableSet, i), true) // `i` is in the mutableSet
1023
+ * assert.equal(HashSet.has(immutableSet, i), false) // `i` is not in the immutableSet
1024
+ * }
1025
+ *
1026
+ * const next = UPPER_BOUND + 1
1027
+ * // When done, mark the set as immutable again
1028
+ * HashSet.endMutation(mutableSet).pipe(
1029
+ * HashSet.add(next) // since this returns a new HashSet, it will not be logged as part of the mutableSet
1030
+ * )
1031
+ * assert.equal(HashSet.has(mutableSet, next), false)
1032
+ *
1033
+ * console.log(HashSet.toValues(immutableSet)) // [0]
1034
+ * console.log(HashSet.toValues(mutableSet).sort((a, b) => a - b)) // [0, 1, 2, 3, ...rest]
1035
+ * ```
1036
+ *
1037
+ * @see Other `HashSet` mutations are {@link module:HashSet.add} {@link module:HashSet.remove} {@link module:HashSet.toggle} {@link module:HashSet.endMutation} {@link module:HashSet.mutate}
195
1038
  */
196
1039
  export declare const beginMutation: <A>(self: HashSet<A>) => HashSet<A>;
197
1040
  /**
198
- * Marks the `HashSet` as immutable.
1041
+ * Makes the `HashSet` immutable again.
199
1042
  *
1043
+ * After calling `endMutation`, operations like {@link add} and {@link remove}
1044
+ * will create new instances of the `HashSet` instead of modifying the existing
1045
+ * one.
1046
+ *
1047
+ * @memberof HashSet
200
1048
  * @since 2.0.0
1049
+ * @example
1050
+ *
1051
+ * ```ts
1052
+ * import { HashSet } from "effect"
1053
+ * import assert from "node:assert/strict"
1054
+ *
1055
+ * // Create a mutable set
1056
+ * const mutableSet = HashSet.beginMutation(HashSet.empty<number>())
1057
+ *
1058
+ * // Add some elements to the mutable set
1059
+ * HashSet.add(mutableSet, 1)
1060
+ * HashSet.add(mutableSet, 2)
1061
+ *
1062
+ * // Before endMutation, operations modify the set in place
1063
+ * const sameSet = HashSet.add(mutableSet, 3)
1064
+ * assert(Object.is(mutableSet, sameSet)) // true - same object reference
1065
+ * assert.deepStrictEqual(HashSet.toValues(mutableSet).sort(), [1, 2, 3])
1066
+ *
1067
+ * // Make the set immutable again
1068
+ * const immutableSet = HashSet.endMutation(mutableSet)
1069
+ *
1070
+ * // endMutation returns the same set instance, now made immutable
1071
+ * assert(Object.is(mutableSet, immutableSet)) // true - same object reference
1072
+ *
1073
+ * // After endMutation, operations create new instances
1074
+ * const newSet = HashSet.add(immutableSet, 4)
1075
+ * assert(!Object.is(immutableSet, newSet)) // false - different object references
1076
+ *
1077
+ * // The original set remains unchanged
1078
+ * assert.deepStrictEqual(HashSet.toValues(immutableSet).sort(), [1, 2, 3])
1079
+ *
1080
+ * // The new set contains the added element
1081
+ * assert.deepStrictEqual(HashSet.toValues(newSet).sort(), [1, 2, 3, 4])
1082
+ * ```
1083
+ *
1084
+ * @see Other `HashSet` mutations are {@link module:HashSet.add} {@link module:HashSet.remove} {@link module:HashSet.toggle} {@link module:HashSet.beginMutation} {@link module:HashSet.mutate}
201
1085
  */
202
1086
  export declare const endMutation: <A>(self: HashSet<A>) => HashSet<A>;
203
1087
  /**
204
1088
  * Mutates the `HashSet` within the context of the provided function.
205
1089
  *
1090
+ * You can consider it a functional abstraction on top of the lower-level
1091
+ * mutation primitives of {@link module:HashSet.beginMutation} `->` `mutable
1092
+ * context` `->` {@link HashSet.endMutation}.
1093
+ *
1094
+ * @memberof HashSet
206
1095
  * @since 2.0.0
1096
+ * @example
1097
+ *
1098
+ * ```ts
1099
+ * // Syntax
1100
+ * import { HashSet, pipe } from "effect"
1101
+ *
1102
+ * // with data-last, a.k.a. pipeable API
1103
+ * pipe(
1104
+ * HashSet.make(1, 2, 3),
1105
+ * HashSet.mutate((set) => {
1106
+ * HashSet.add(set, 4)
1107
+ * HashSet.remove(set, 1)
1108
+ * })
1109
+ * )
1110
+ *
1111
+ * // or piped with the pipe function
1112
+ * HashSet.make(1, 2, 3).pipe(
1113
+ * HashSet.mutate((set) => {
1114
+ * HashSet.add(set, 4)
1115
+ * HashSet.remove(set, 1)
1116
+ * })
1117
+ * )
1118
+ *
1119
+ * // or with data-first API
1120
+ * HashSet.mutate(HashSet.make(1, 2, 3), (set) => {
1121
+ * HashSet.add(set, 4)
1122
+ * HashSet.remove(set, 1)
1123
+ * })
1124
+ * ```
1125
+ *
1126
+ * @see Other `HashSet` mutations are {@link module:HashSet.add} {@link module:HashSet.remove} {@link module:HashSet.toggle} {@link module:HashSet.beginMutation} {@link module:HashSet.endMutation}
207
1127
  */
208
1128
  export declare const mutate: {
209
1129
  /**
210
- * Mutates the `HashSet` within the context of the provided function.
1130
+ * @example
211
1131
  *
212
- * @since 2.0.0
1132
+ * ```ts
1133
+ * // `data-last` a.k.a. `pipeable` API
1134
+ * import { HashSet, pipe } from "effect"
1135
+ * import assert from "node:assert/strict"
1136
+ *
1137
+ * // Create a set with initial values
1138
+ * const immutableSet = HashSet.make(1, 2, 3)
1139
+ *
1140
+ * // Use mutate to perform multiple operations efficiently
1141
+ * const result = pipe(
1142
+ * immutableSet,
1143
+ * HashSet.mutate((set) => {
1144
+ * assert.equal(Object.is(immutableSet, set), false)
1145
+ *
1146
+ * // The set is temporarily mutable inside this function
1147
+ * const mod1 = HashSet.add(set, 4)
1148
+ * const mod2 = HashSet.remove(set, 1)
1149
+ * assert.equal(Object.is(mod1, mod2), true) // they are the same object by reference
1150
+ * })
1151
+ * )
1152
+ *
1153
+ * // The original set is unchanged
1154
+ * assert.equal(Object.is(immutableSet, result), false)
1155
+ * assert.deepStrictEqual(
1156
+ * HashSet.toValues(immutableSet).sort(),
1157
+ * [1, 2, 3]
1158
+ * )
1159
+ *
1160
+ * // The result contains the mutations
1161
+ * assert.deepStrictEqual(HashSet.toValues(result).sort(), [2, 3, 4])
1162
+ * ```
213
1163
  */
214
1164
  <A>(f: (set: HashSet<A>) => void): (self: HashSet<A>) => HashSet<A>;
215
1165
  /**
216
- * Mutates the `HashSet` within the context of the provided function.
1166
+ * @example
1167
+ *
1168
+ * ```ts
1169
+ * // `data-first` API
1170
+ * import { HashSet } from "effect"
1171
+ * import assert from "node:assert/strict"
217
1172
  *
218
- * @since 2.0.0
1173
+ * // Create a set with initial values
1174
+ * const immutableSet = HashSet.make(1, 2, 3)
1175
+ *
1176
+ * // Use mutate with data-first API
1177
+ * const result = HashSet.mutate(immutableSet, (set) => {
1178
+ * // The set is temporarily mutable inside this function
1179
+ * HashSet.add(set, 4)
1180
+ * HashSet.remove(set, 1)
1181
+ * })
1182
+ *
1183
+ * // The original set is unchanged
1184
+ * assert.equal(Object.is(immutableSet, result), false)
1185
+ * assert.deepStrictEqual(
1186
+ * HashSet.toValues(immutableSet).sort(),
1187
+ * [1, 2, 3]
1188
+ * )
1189
+ *
1190
+ * // The result contains the mutations
1191
+ * assert.deepStrictEqual(HashSet.toValues(result).sort(), [2, 3, 4])
1192
+ * ```
219
1193
  */
220
1194
  <A>(self: HashSet<A>, f: (set: HashSet<A>) => void): HashSet<A>;
221
1195
  };
222
1196
  /**
223
1197
  * Adds a value to the `HashSet`.
224
1198
  *
1199
+ * Time complexity: **`O(1)`** average
1200
+ *
1201
+ * @remarks
1202
+ * Remember that a `HashSet` is a collection of unique values, so adding a value
1203
+ * that already exists in the `HashSet` will not add a duplicate.
1204
+ *
1205
+ * Remember that HashSet is an immutable data structure, so the `add` function,
1206
+ * like all other functions that modify the HashSet, will return a new HashSet
1207
+ * with the added value.
1208
+ * @memberof HashSet
225
1209
  * @since 2.0.0
1210
+ * @example
1211
+ *
1212
+ * ```ts
1213
+ * // Syntax
1214
+ * import { HashSet, pipe } from "effect"
1215
+ *
1216
+ * // with data-last, a.k.a. pipeable API
1217
+ * pipe(HashSet.empty(), HashSet.add(0), HashSet.add(0))
1218
+ *
1219
+ * // or piped with the pipe function
1220
+ * HashSet.empty().pipe(HashSet.add(0))
1221
+ *
1222
+ * // or with data-first API
1223
+ * HashSet.add(HashSet.empty(), 0)
1224
+ * ```
1225
+ *
1226
+ * @see Other `HashSet` mutations are {@link module:HashSet.remove} {@link module:HashSet.toggle} {@link module:HashSet.beginMutation} {@link module:HashSet.endMutation} {@link module:HashSet.mutate}
226
1227
  */
227
1228
  export declare const add: {
228
1229
  /**
229
- * Adds a value to the `HashSet`.
1230
+ * @example
1231
+ *
1232
+ * ```ts
1233
+ * // `data-last` a.k.a. `pipeable` API
1234
+ * import { HashSet, pipe } from "effect"
1235
+ * import assert from "node:assert/strict"
230
1236
  *
231
- * @since 2.0.0
1237
+ * assert.deepStrictEqual(
1238
+ * pipe(
1239
+ * HashSet.empty<number>(), // HashSet.HashSet<number>
1240
+ * HashSet.add(0),
1241
+ * HashSet.add(1),
1242
+ * HashSet.add(1),
1243
+ * HashSet.add(2),
1244
+ * HashSet.toValues
1245
+ * ),
1246
+ * Array.of(0, 1, 2)
1247
+ * )
1248
+ * ```
232
1249
  */
233
1250
  <A>(value: A): (self: HashSet<A>) => HashSet<A>;
234
1251
  /**
235
- * Adds a value to the `HashSet`.
1252
+ * @example
236
1253
  *
237
- * @since 2.0.0
1254
+ * ```ts
1255
+ * // `data-first` API
1256
+ * import { HashSet, pipe } from "effect"
1257
+ * import assert from "node:assert/strict"
1258
+ *
1259
+ * const empty = HashSet.empty<number>()
1260
+ * const withZero = HashSet.add(empty, 0)
1261
+ * const withOne = HashSet.add(withZero, 1)
1262
+ * const withTwo = HashSet.add(withOne, 2)
1263
+ * const withTwoTwo = HashSet.add(withTwo, 2)
1264
+ *
1265
+ * assert.deepStrictEqual(HashSet.toValues(withTwoTwo), Array.of(0, 1, 2))
1266
+ * ```
238
1267
  */
239
1268
  <A>(self: HashSet<A>, value: A): HashSet<A>;
240
1269
  };
241
1270
  /**
242
1271
  * Removes a value from the `HashSet`.
243
1272
  *
1273
+ * Time complexity: **`O(1)`** average
1274
+ *
1275
+ * @memberof HashSet
244
1276
  * @since 2.0.0
1277
+ * @example
1278
+ *
1279
+ * ```ts
1280
+ * // Syntax
1281
+ * import { HashSet, pipe } from "effect"
1282
+ *
1283
+ * // with `data-last`, a.k.a. `pipeable` API
1284
+ * pipe(HashSet.make(0, 1, 2), HashSet.remove(0))
1285
+ *
1286
+ * // or piped with the pipe function
1287
+ * HashSet.make(0, 1, 2).pipe(HashSet.remove(0))
1288
+ *
1289
+ * // or with `data-first` API
1290
+ * HashSet.remove(HashSet.make(0, 1, 2), 0)
1291
+ * ```
1292
+ *
1293
+ * @see Other `HashSet` mutations are {@link module:HashSet.add} {@link module:HashSet.toggle} {@link module:HashSet.beginMutation} {@link module:HashSet.endMutation} {@link module:HashSet.mutate}
245
1294
  */
246
1295
  export declare const remove: {
247
1296
  /**
248
- * Removes a value from the `HashSet`.
1297
+ * @example
1298
+ *
1299
+ * ```ts
1300
+ * // `data-last` a.k.a. `pipeable` API
1301
+ * import { HashSet, pipe } from "effect"
1302
+ * import * as assert from "node:assert/strict"
249
1303
  *
250
- * @since 2.0.0
1304
+ * const set = HashSet.make(0, 1, 2)
1305
+ * const result = pipe(set, HashSet.remove(0))
1306
+ *
1307
+ * assert.equal(pipe(result, HashSet.has(0)), false) // it has correctly removed 0
1308
+ * assert.equal(pipe(set, HashSet.has(0)), true) // it does not mutate the original set
1309
+ * assert.equal(pipe(result, HashSet.has(1)), true)
1310
+ * assert.equal(pipe(result, HashSet.has(2)), true)
1311
+ * ```
251
1312
  */
252
1313
  <A>(value: A): (self: HashSet<A>) => HashSet<A>;
253
1314
  /**
254
- * Removes a value from the `HashSet`.
1315
+ * @example
1316
+ *
1317
+ * ```ts
1318
+ * // `data-first` API
1319
+ * import { HashSet, pipe } from "effect"
1320
+ * import * as assert from "node:assert/strict"
1321
+ *
1322
+ * const set = HashSet.make(0, 1, 2)
1323
+ * const result = HashSet.remove(set, 0)
255
1324
  *
256
- * @since 2.0.0
1325
+ * assert.equal(HashSet.has(result, 0), false) // it has correctly removed 0
1326
+ * assert.equal(HashSet.has(set, 0), true) // it does not mutate the original set
1327
+ * assert.equal(HashSet.has(result, 1), true)
1328
+ * assert.equal(HashSet.has(result, 2), true)
1329
+ * ```
257
1330
  */
258
1331
  <A>(self: HashSet<A>, value: A): HashSet<A>;
259
1332
  };
260
1333
  /**
261
- * Computes the set difference between this `HashSet` and the specified
262
- * `Iterable<A>`.
1334
+ * Computes the set difference `(A - B)` between this `HashSet` and the
1335
+ * specified `Iterable<A>`.
1336
+ *
1337
+ * Time complexity: **`O(n)`** where n is the number of elements in the set
263
1338
  *
264
1339
  * **NOTE**: the hash and equal of the values in both the set and the iterable
265
- * must be the same.
1340
+ * must be the same; meaning we cannot compute a difference between a `HashSet
1341
+ * of bananas` and a `HashSet of elephants` as they are not the same type and
1342
+ * won't implement the Equal trait in the same way.
266
1343
  *
1344
+ * @memberof HashSet
267
1345
  * @since 2.0.0
1346
+ * @example
1347
+ *
1348
+ * ```ts
1349
+ * // Syntax
1350
+ * import { HashSet, pipe } from "effect"
1351
+ *
1352
+ * // with data-last, a.k.a. pipeable API
1353
+ * pipe(HashSet.make(1, 2, 3), HashSet.difference(HashSet.make(3, 4, 5)))
1354
+ *
1355
+ * // or piped with the pipe function
1356
+ * HashSet.make(1, 2, 3).pipe(HashSet.difference(HashSet.make(3, 4, 5)))
1357
+ *
1358
+ * // or with data-first API
1359
+ * HashSet.difference(HashSet.make(1, 2, 3), HashSet.make(3, 4, 5))
1360
+ * ```
1361
+ *
1362
+ * @see Other `HashSet` operations are {@link module:HashSet.intersection} {@link module:HashSet.union}
268
1363
  */
269
1364
  export declare const difference: {
270
1365
  /**
271
- * Computes the set difference between this `HashSet` and the specified
272
- * `Iterable<A>`.
1366
+ * @example
1367
+ *
1368
+ * ```ts
1369
+ * // `data-last` a.k.a. `pipeable` API
1370
+ * import { HashSet, pipe } from "effect"
1371
+ * import * as assert from "node:assert/strict"
1372
+ *
1373
+ * // Create two sets with some overlapping elements
1374
+ * const thisSet = HashSet.make(1, 2, 3)
1375
+ * const thatIterable = HashSet.make(3, 4, 5)
1376
+ *
1377
+ * // Compute the difference (elements in thisSet that are not in thatIterable)
1378
+ * const result = pipe(thisSet, HashSet.difference(thatIterable))
273
1379
  *
274
- * **NOTE**: the hash and equal of the values in both the set and the iterable
275
- * must be the same.
1380
+ * // The result contains only elements from thisSet that are not in thatIterable
1381
+ * assert.deepStrictEqual(HashSet.toValues(result).sort(), [1, 2])
276
1382
  *
277
- * @since 2.0.0
1383
+ * // The original sets are unchanged
1384
+ * assert.deepStrictEqual(HashSet.toValues(thisSet).sort(), [1, 2, 3])
1385
+ * assert.deepStrictEqual(
1386
+ * HashSet.toValues(thatIterable).sort(),
1387
+ * [3, 4, 5]
1388
+ * )
1389
+ *
1390
+ * // You can also use arrays or other iterables
1391
+ * const diffWithArray = pipe(thisSet, HashSet.difference([3, 4]))
1392
+ * assert.deepStrictEqual(HashSet.toValues(diffWithArray).sort(), [1, 2])
1393
+ * ```
278
1394
  */
279
1395
  <A>(that: Iterable<A>): (self: HashSet<A>) => HashSet<A>;
280
1396
  /**
281
- * Computes the set difference between this `HashSet` and the specified
282
- * `Iterable<A>`.
1397
+ * @example
1398
+ *
1399
+ * ```ts
1400
+ * // `data-first` API
1401
+ * import { HashSet } from "effect"
1402
+ * import * as assert from "node:assert/strict"
1403
+ *
1404
+ * // Create two sets with some overlapping elements
1405
+ * const thisSet = HashSet.make(1, 2, 3)
1406
+ * const thatIterable = HashSet.make(3, 4, 5)
283
1407
  *
284
- * **NOTE**: the hash and equal of the values in both the set and the iterable
285
- * must be the same.
1408
+ * // Compute the difference using data-first API
1409
+ * const result = HashSet.difference(thisSet, thatIterable)
286
1410
  *
287
- * @since 2.0.0
1411
+ * // The result contains only elements from thisSet that are not in thatIterable
1412
+ * assert.deepStrictEqual(HashSet.toValues(result).sort(), [1, 2])
1413
+ *
1414
+ * // The original sets are unchanged
1415
+ * assert.deepStrictEqual(HashSet.toValues(thisSet).sort(), [1, 2, 3])
1416
+ * assert.deepStrictEqual(
1417
+ * HashSet.toValues(thatIterable).sort(),
1418
+ * [3, 4, 5]
1419
+ * )
1420
+ *
1421
+ * // You can also compute the difference in the other direction
1422
+ * const reverseResult = HashSet.difference(thatIterable, thisSet)
1423
+ * assert.deepStrictEqual(HashSet.toValues(reverseResult).sort(), [4, 5])
1424
+ * ```
288
1425
  */
289
1426
  <A>(self: HashSet<A>, that: Iterable<A>): HashSet<A>;
290
1427
  };
291
1428
  /**
292
1429
  * Returns a `HashSet` of values which are present in both this set and that
293
- * `Iterable<A>`.
1430
+ * `Iterable<A>`. Computes set intersection (A ∩ B)
1431
+ *
1432
+ * Time complexity: **`O(n)`** where n is the number of elements in the smaller
1433
+ * set
294
1434
  *
295
1435
  * **NOTE**: the hash and equal of the values in both the set and the iterable
296
1436
  * must be the same.
297
1437
  *
1438
+ * @memberof HashSet
298
1439
  * @since 2.0.0
1440
+ * @example
1441
+ *
1442
+ * ```ts
1443
+ * // Syntax
1444
+ * import { HashSet, pipe } from "effect"
1445
+ *
1446
+ * // with data-last, a.k.a. pipeable API
1447
+ * pipe(HashSet.make(1, 2, 3), HashSet.intersection(HashSet.make(2, 3, 4)))
1448
+ *
1449
+ * // or piped with the pipe function
1450
+ * HashSet.make(1, 2, 3).pipe(HashSet.intersection(HashSet.make(2, 3, 4)))
1451
+ *
1452
+ * // or with data-first API
1453
+ * HashSet.intersection(HashSet.make(1, 2, 3), HashSet.make(2, 3, 4))
1454
+ * ```
1455
+ *
1456
+ * @see Other `HashSet` operations are {@link module:HashSet.difference} {@link module:HashSet.union}
299
1457
  */
300
1458
  export declare const intersection: {
301
1459
  /**
302
- * Returns a `HashSet` of values which are present in both this set and that
303
- * `Iterable<A>`.
1460
+ * @example
1461
+ *
1462
+ * ```ts
1463
+ * // `data-last` a.k.a. `pipeable` API
1464
+ * import { HashSet, pipe } from "effect"
1465
+ * import * as assert from "node:assert/strict"
304
1466
  *
305
- * **NOTE**: the hash and equal of the values in both the set and the iterable
306
- * must be the same.
1467
+ * // Create two sets with some overlapping elements
1468
+ * const set1 = HashSet.make(1, 2, 3)
1469
+ * const set2 = HashSet.make(2, 3, 4)
307
1470
  *
308
- * @since 2.0.0
1471
+ * // Compute the intersection (elements that are in both sets)
1472
+ * const result = pipe(set1, HashSet.intersection(set2))
1473
+ *
1474
+ * // The result contains only elements that are in both sets
1475
+ * assert.deepStrictEqual(HashSet.toValues(result).sort(), [2, 3])
1476
+ *
1477
+ * // The original sets are unchanged
1478
+ * assert.deepStrictEqual(HashSet.toValues(set1).sort(), [1, 2, 3])
1479
+ * assert.deepStrictEqual(HashSet.toValues(set2).sort(), [2, 3, 4])
1480
+ *
1481
+ * // You can also use arrays or other iterables
1482
+ * const intersectWithArray = pipe(set1, HashSet.intersection([2, 3, 5]))
1483
+ * assert.deepStrictEqual(
1484
+ * HashSet.toValues(intersectWithArray).sort(),
1485
+ * [2, 3]
1486
+ * )
1487
+ * ```
309
1488
  */
310
1489
  <A>(that: Iterable<A>): (self: HashSet<A>) => HashSet<A>;
311
1490
  /**
312
- * Returns a `HashSet` of values which are present in both this set and that
313
- * `Iterable<A>`.
1491
+ * @example
1492
+ *
1493
+ * ```ts
1494
+ * // `data-first` API
1495
+ * import { HashSet } from "effect"
1496
+ * import * as assert from "node:assert/strict"
1497
+ *
1498
+ * // Create two sets with some overlapping elements
1499
+ * const set1 = HashSet.make(1, 2, 3)
1500
+ * const set2 = HashSet.make(2, 3, 4)
314
1501
  *
315
- * **NOTE**: the hash and equal of the values in both the set and the iterable
316
- * must be the same.
1502
+ * // Compute the intersection using data-first API
1503
+ * const result = HashSet.intersection(set1, set2)
317
1504
  *
318
- * @since 2.0.0
1505
+ * // The result contains only elements that are in both sets
1506
+ * assert.deepStrictEqual(HashSet.toValues(result).sort(), [2, 3])
1507
+ *
1508
+ * // The original sets are unchanged
1509
+ * assert.deepStrictEqual(HashSet.toValues(set1).sort(), [1, 2, 3])
1510
+ * assert.deepStrictEqual(HashSet.toValues(set2).sort(), [2, 3, 4])
1511
+ *
1512
+ * // You can also use arrays or other iterables
1513
+ * const intersectWithArray = HashSet.intersection(set1, [2, 3, 5])
1514
+ * assert.deepStrictEqual(
1515
+ * HashSet.toValues(intersectWithArray).sort(),
1516
+ * [2, 3]
1517
+ * )
1518
+ * ```
319
1519
  */
320
1520
  <A>(self: HashSet<A>, that: Iterable<A>): HashSet<A>;
321
1521
  };
322
1522
  /**
323
- * Computes the set union `(`self` + `that`)` between this `HashSet` and the
1523
+ * Computes the set union `( self that )` between this `HashSet` and the
324
1524
  * specified `Iterable<A>`.
325
1525
  *
1526
+ * Time complexity: **`O(n)`** where n is the number of elements in the set
1527
+ *
326
1528
  * **NOTE**: the hash and equal of the values in both the set and the iterable
327
1529
  * must be the same.
328
1530
  *
1531
+ * @memberof HashSet
329
1532
  * @since 2.0.0
1533
+ * @example
1534
+ *
1535
+ * ```ts
1536
+ * // Syntax
1537
+ * import { HashSet, pipe } from "effect"
1538
+ *
1539
+ * // with data-last, a.k.a. pipeable API
1540
+ * pipe(HashSet.make(1, 2, 3), HashSet.union(HashSet.make(3, 4, 5)))
1541
+ *
1542
+ * // or piped with the pipe function
1543
+ * HashSet.make(1, 2, 3).pipe(HashSet.union(HashSet.make(3, 4, 5)))
1544
+ *
1545
+ * // or with data-first API
1546
+ * HashSet.union(HashSet.make(1, 2, 3), HashSet.make(3, 4, 5))
1547
+ * ```
1548
+ *
1549
+ * @see Other `HashSet` operations are {@link module:HashSet.difference} {@link module:HashSet.intersection}
330
1550
  */
331
1551
  export declare const union: {
332
1552
  /**
333
- * Computes the set union `(`self` + `that`)` between this `HashSet` and the
334
- * specified `Iterable<A>`.
1553
+ * @example
1554
+ *
1555
+ * ```ts
1556
+ * // `data-last` a.k.a. `pipeable` API
1557
+ * import { HashSet, pipe } from "effect"
1558
+ * import * as assert from "node:assert/strict"
1559
+ *
1560
+ * // Create two sets with some overlapping elements
1561
+ * const selfSet = HashSet.make(1, 2, 3)
1562
+ * const thatIterable = HashSet.make(3, 4, 5)
1563
+ *
1564
+ * // Compute the union (all elements from both sets)
1565
+ * const result = pipe(selfSet, HashSet.union(thatIterable))
335
1566
  *
336
- * **NOTE**: the hash and equal of the values in both the set and the iterable
337
- * must be the same.
1567
+ * // The result contains all elements from both sets (without duplicates)
1568
+ * assert.deepStrictEqual(
1569
+ * HashSet.toValues(result).sort(),
1570
+ * [1, 2, 3, 4, 5]
1571
+ * )
338
1572
  *
339
- * @since 2.0.0
1573
+ * // The original sets are unchanged
1574
+ * assert.deepStrictEqual(HashSet.toValues(selfSet).sort(), [1, 2, 3])
1575
+ * assert.deepStrictEqual(
1576
+ * HashSet.toValues(thatIterable).sort(),
1577
+ * [3, 4, 5]
1578
+ * )
1579
+ *
1580
+ * // You can also use arrays or other iterables
1581
+ * const unionWithArray = pipe(selfSet, HashSet.union([4, 5, 6]))
1582
+ * assert.deepStrictEqual(
1583
+ * HashSet.toValues(unionWithArray).sort(),
1584
+ * [1, 2, 3, 4, 5, 6]
1585
+ * )
1586
+ * ```
340
1587
  */
341
1588
  <A>(that: Iterable<A>): (self: HashSet<A>) => HashSet<A>;
342
1589
  /**
343
- * Computes the set union `(`self` + `that`)` between this `HashSet` and the
344
- * specified `Iterable<A>`.
1590
+ * @example
1591
+ *
1592
+ * ```ts
1593
+ * // `data-first` API
1594
+ * import { HashSet } from "effect"
1595
+ * import * as assert from "node:assert/strict"
1596
+ *
1597
+ * // Create two sets with some overlapping elements
1598
+ * const selfSet = HashSet.make(1, 2, 3)
1599
+ * const thatIterable = HashSet.make(3, 4, 5)
345
1600
  *
346
- * **NOTE**: the hash and equal of the values in both the set and the iterable
347
- * must be the same.
1601
+ * // Compute the union using data-first API
1602
+ * const result = HashSet.union(selfSet, thatIterable)
348
1603
  *
349
- * @since 2.0.0
1604
+ * // The result contains all elements from both sets (without duplicates)
1605
+ * assert.deepStrictEqual(
1606
+ * HashSet.toValues(result).sort(),
1607
+ * [1, 2, 3, 4, 5]
1608
+ * )
1609
+ *
1610
+ * // The original sets are unchanged
1611
+ * assert.deepStrictEqual(HashSet.toValues(selfSet).sort(), [1, 2, 3])
1612
+ * assert.deepStrictEqual(
1613
+ * HashSet.toValues(thatIterable).sort(),
1614
+ * [3, 4, 5]
1615
+ * )
1616
+ *
1617
+ * // You can also use arrays or other iterables
1618
+ * const unionWithArray = HashSet.union(selfSet, [4, 5, 6])
1619
+ * assert.deepStrictEqual(
1620
+ * HashSet.toValues(unionWithArray).sort(),
1621
+ * [1, 2, 3, 4, 5, 6]
1622
+ * )
1623
+ * ```
350
1624
  */
351
1625
  <A>(self: HashSet<A>, that: Iterable<A>): HashSet<A>;
352
1626
  };
@@ -355,147 +1629,482 @@ export declare const union: {
355
1629
  * will be removed from the `HashSet`, otherwise the value will be added to the
356
1630
  * `HashSet`.
357
1631
  *
1632
+ * Time complexity: **`O(1)`** average
1633
+ *
1634
+ * @memberof HashSet
358
1635
  * @since 2.0.0
1636
+ * @example
1637
+ *
1638
+ * ```ts
1639
+ * // Syntax
1640
+ * import { HashSet, pipe } from "effect"
1641
+ *
1642
+ * // with `data-last`, a.k.a. `pipeable` API
1643
+ * pipe(HashSet.make(0, 1, 2), HashSet.toggle(0))
1644
+ *
1645
+ * // or piped with the pipe function
1646
+ * HashSet.make(0, 1, 2).pipe(HashSet.toggle(0))
1647
+ *
1648
+ * // or with `data-first` API
1649
+ * HashSet.toggle(HashSet.make(0, 1, 2), 0)
1650
+ * ```
1651
+ *
1652
+ * @returns A new `HashSet` where the toggled value is being either added or
1653
+ * removed based on the initial `HashSet` state.
1654
+ * @see Other `HashSet` mutations are {@link module:HashSet.add} {@link module:HashSet.remove} {@link module:HashSet.beginMutation} {@link module:HashSet.endMutation} {@link module:HashSet.mutate}
359
1655
  */
360
1656
  export declare const toggle: {
361
1657
  /**
362
- * Checks if a value is present in the `HashSet`. If it is present, the value
363
- * will be removed from the `HashSet`, otherwise the value will be added to the
364
- * `HashSet`.
1658
+ * @example
365
1659
  *
366
- * @since 2.0.0
1660
+ * ```ts
1661
+ * // `data-last` a.k.a. `pipeable` API
1662
+ * import { HashSet, pipe } from "effect"
1663
+ * import assert from "node:assert/strict"
1664
+ *
1665
+ * // arrange
1666
+ * let set = HashSet.make(0, 1, 2)
1667
+ *
1668
+ * // assert 1: 0 is in the set
1669
+ * assert.equal(pipe(set, HashSet.has(0)), true)
1670
+ *
1671
+ * // act 2: toggle 0 once on the set
1672
+ * set = pipe(set, HashSet.toggle(0))
1673
+ *
1674
+ * // assert 2: 0 is not in the set any longer
1675
+ * assert.equal(pipe(set, HashSet.has(0)), false)
1676
+ *
1677
+ * // act 3: toggle 0 once again on the set
1678
+ * set = pipe(set, HashSet.toggle(0))
1679
+ *
1680
+ * // assert 3: 0 in now back in the set
1681
+ * assert.equal(pipe(set, HashSet.has(0)), true)
1682
+ * ```
367
1683
  */
368
1684
  <A>(value: A): (self: HashSet<A>) => HashSet<A>;
369
1685
  /**
370
- * Checks if a value is present in the `HashSet`. If it is present, the value
371
- * will be removed from the `HashSet`, otherwise the value will be added to the
372
- * `HashSet`.
1686
+ * @example
1687
+ *
1688
+ * ```ts
1689
+ * // `data-first` API
1690
+ * import { HashSet, pipe } from "effect"
1691
+ * import assert from "node:assert/strict"
1692
+ *
1693
+ * // arrange
1694
+ * let set = HashSet.make(0, 1, 2)
1695
+ *
1696
+ * // assert 1: 0 is in the set
1697
+ * assert.equal(HashSet.has(set, 0), true)
1698
+ *
1699
+ * // act 2: toggle 0 once on the set
1700
+ * set = HashSet.toggle(set, 0)
1701
+ *
1702
+ * // assert 2: 0 is not in the set any longer
1703
+ * assert.equal(HashSet.has(set, 0), false)
1704
+ *
1705
+ * // act 3: toggle 0 once again on the set
1706
+ * set = HashSet.toggle(set, 0)
373
1707
  *
374
- * @since 2.0.0
1708
+ * // assert 3: 0 in now back in the set
1709
+ * assert.equal(HashSet.has(set, 0), true)
1710
+ * ```
375
1711
  */
376
1712
  <A>(self: HashSet<A>, value: A): HashSet<A>;
377
1713
  };
378
1714
  /**
379
1715
  * Maps over the values of the `HashSet` using the specified function.
380
1716
  *
1717
+ * The time complexity is of **`O(n)`**.
1718
+ *
1719
+ * @memberof HashSet
381
1720
  * @since 2.0.0
382
1721
  * @category mapping
1722
+ * @example
1723
+ *
1724
+ * ```ts
1725
+ * // Syntax
1726
+ * import { HashSet, pipe } from "effect"
1727
+ *
1728
+ * // with `data-last`, a.k.a. `pipeable` API
1729
+ * pipe(
1730
+ * HashSet.make(0, 1, 2), // HashSet.HashSet<number>
1731
+ * HashSet.map(String) // HashSet.HashSet<string>
1732
+ * )
1733
+ *
1734
+ * // or piped with the pipe method
1735
+ * HashSet.make(0, 1, 2).pipe(HashSet.map(String))
1736
+ *
1737
+ * // or with `data-first` API
1738
+ * HashSet.map(HashSet.make(0, 1, 2), String)
1739
+ * ```
383
1740
  */
384
1741
  export declare const map: {
385
1742
  /**
386
- * Maps over the values of the `HashSet` using the specified function.
1743
+ * @example
1744
+ *
1745
+ * ```ts
1746
+ * import { HashSet, pipe } from "effect"
1747
+ * import * as assert from "node:assert/strict"
387
1748
  *
388
- * @since 2.0.0
389
- * @category mapping
1749
+ * assert.deepStrictEqual(
1750
+ * pipe(
1751
+ * HashSet.make(0, 1, 2), // HashSet.HashSet<number>
1752
+ * HashSet.map((n) => String(n + 1)) // HashSet.HashSet<String>
1753
+ * ),
1754
+ * HashSet.make("1", "2", "3")
1755
+ * )
1756
+ * ```
390
1757
  */
391
1758
  <A, B>(f: (a: A) => B): (self: HashSet<A>) => HashSet<B>;
392
1759
  /**
393
- * Maps over the values of the `HashSet` using the specified function.
1760
+ * @example
394
1761
  *
395
- * @since 2.0.0
396
- * @category mapping
1762
+ * ```ts
1763
+ * import { HashSet, pipe } from "effect"
1764
+ * import * as assert from "node:assert/strict"
1765
+ *
1766
+ * assert.deepStrictEqual(
1767
+ * HashSet.map(
1768
+ * HashSet.make(0, 1, 2), // HashSet.HashSet<number>
1769
+ * (n) => String(n + 1)
1770
+ * ), // HashSet.HashSet<String>
1771
+ * HashSet.make("1", "2", "3")
1772
+ * )
1773
+ * ```
397
1774
  */
398
1775
  <A, B>(self: HashSet<A>, f: (a: A) => B): HashSet<B>;
399
1776
  };
400
1777
  /**
401
1778
  * Chains over the values of the `HashSet` using the specified function.
402
1779
  *
1780
+ * The time complexity is of **`O(n)`**.
1781
+ *
1782
+ * @memberof HashSet
403
1783
  * @since 2.0.0
404
1784
  * @category sequencing
1785
+ * @example
1786
+ *
1787
+ * ```ts
1788
+ * // Syntax
1789
+ * import { HashSet, pipe } from "effect"
1790
+ *
1791
+ * // with `data-last`, a.k.a. `pipeable` API
1792
+ * pipe(
1793
+ * HashSet.make(0, 1, 2), // HashSet.HashSet<number>
1794
+ * HashSet.flatMap((n) => Array.of(String(n))) // HashSet.HashSet<string>
1795
+ * )
1796
+ *
1797
+ * // or piped with the pipe method
1798
+ * HashSet.make(0, 1, 2) // HashSet.HashSet<number>
1799
+ * .pipe(
1800
+ * HashSet.flatMap((n) => Array.of(String(n))) // HashSet.HashSet<string>
1801
+ * )
1802
+ *
1803
+ * // or with `data-first` API
1804
+ * HashSet.flatMap(HashSet.make(0, 1, 2), (n) => Array.of(String(n)))
1805
+ * ```
405
1806
  */
406
1807
  export declare const flatMap: {
407
1808
  /**
408
- * Chains over the values of the `HashSet` using the specified function.
1809
+ * @example
1810
+ *
1811
+ * ```ts
1812
+ * import { HashSet, pipe, List } from "effect"
1813
+ * import * as assert from "node:assert/strict"
409
1814
  *
410
- * @since 2.0.0
411
- * @category sequencing
1815
+ * assert.deepStrictEqual(
1816
+ * pipe(
1817
+ * HashSet.make(0, 1, 2),
1818
+ * HashSet.flatMap((n) => List.of(String(n * n))) // needs to return an Iterable
1819
+ * ),
1820
+ * HashSet.make("0", "1", "4")
1821
+ * )
1822
+ * ```
412
1823
  */
413
1824
  <A, B>(f: (a: A) => Iterable<B>): (self: HashSet<A>) => HashSet<B>;
414
1825
  /**
415
- * Chains over the values of the `HashSet` using the specified function.
1826
+ * @example
1827
+ *
1828
+ * ```ts
1829
+ * import { HashSet, pipe, List } from "effect"
1830
+ * import * as assert from "node:assert/strict"
416
1831
  *
417
- * @since 2.0.0
418
- * @category sequencing
1832
+ * assert.deepStrictEqual(
1833
+ * HashSet.flatMap(HashSet.make(0, 1, 2), (n) =>
1834
+ * List.of(String(n * n * n))
1835
+ * ), // needs to return an Iterable
1836
+ * HashSet.make("0", "1", "8")
1837
+ * )
1838
+ * ```
419
1839
  */
420
1840
  <A, B>(self: HashSet<A>, f: (a: A) => Iterable<B>): HashSet<B>;
421
1841
  };
422
1842
  /**
423
1843
  * Applies the specified function to the values of the `HashSet`.
424
1844
  *
1845
+ * The time complexity is of **`O(n)`**.
1846
+ *
1847
+ * @memberof HashSet
425
1848
  * @since 2.0.0
426
1849
  * @category traversing
1850
+ * @example
1851
+ *
1852
+ * ```ts
1853
+ * // Syntax
1854
+ * import { HashSet, pipe } from "effect"
1855
+ *
1856
+ * // with `data-last`, a.k.a. `pipeable` API
1857
+ * pipe(HashSet.make(0, 1, 2), HashSet.forEach(console.log)) // logs: 0 1 2
1858
+ *
1859
+ * // or piped with the pipe method
1860
+ * HashSet.make(0, 1, 2).pipe(HashSet.forEach(console.log)) // logs: 0 1 2
1861
+ *
1862
+ * // or with `data-first` API
1863
+ * HashSet.forEach(HashSet.make(0, 1, 2), console.log) // logs: 0 1 2
1864
+ * ```
427
1865
  */
428
1866
  export declare const forEach: {
429
1867
  /**
430
- * Applies the specified function to the values of the `HashSet`.
1868
+ * @example
1869
+ *
1870
+ * ```ts
1871
+ * import { HashSet, pipe } from "effect"
1872
+ * import * as assert from "node:assert/strict"
1873
+ *
1874
+ * const result: Array<number> = []
1875
+ *
1876
+ * pipe(
1877
+ * HashSet.make(0, 1, 2),
1878
+ * HashSet.forEach((n): void => {
1879
+ * result.push(n)
1880
+ * })
1881
+ * )
431
1882
  *
432
- * @since 2.0.0
433
- * @category traversing
1883
+ * assert.deepStrictEqual(result, [0, 1, 2])
1884
+ * ```
434
1885
  */
435
1886
  <A>(f: (value: A) => void): (self: HashSet<A>) => void;
436
1887
  /**
437
- * Applies the specified function to the values of the `HashSet`.
1888
+ * @example
438
1889
  *
439
- * @since 2.0.0
440
- * @category traversing
1890
+ * ```ts
1891
+ * import { HashSet, pipe } from "effect"
1892
+ * import * as assert from "node:assert/strict"
1893
+ *
1894
+ * const result: Array<number> = []
1895
+ *
1896
+ * HashSet.forEach(HashSet.make(0, 1, 2), (n): void => {
1897
+ * result.push(n)
1898
+ * })
1899
+ *
1900
+ * assert.deepStrictEqual(result, [0, 1, 2])
1901
+ * ```
441
1902
  */
442
1903
  <A>(self: HashSet<A>, f: (value: A) => void): void;
443
1904
  };
444
1905
  /**
445
1906
  * Reduces the specified state over the values of the `HashSet`.
446
1907
  *
1908
+ * The time complexity is of **`O(n)`**.
1909
+ *
1910
+ * @memberof HashSet
447
1911
  * @since 2.0.0
448
1912
  * @category folding
1913
+ * @example
1914
+ *
1915
+ * ```ts
1916
+ * // Syntax
1917
+ * import { HashSet, pipe } from "effect"
1918
+ *
1919
+ * const sum = (a: number, b: number): number => a + b
1920
+ *
1921
+ * // with `data-last`, a.k.a. `pipeable` API
1922
+ * pipe(HashSet.make(0, 1, 2), HashSet.reduce(0, sum))
1923
+ *
1924
+ * // or with the pipe method
1925
+ * HashSet.make(0, 1, 2).pipe(HashSet.reduce(0, sum))
1926
+ *
1927
+ * // or with `data-first` API
1928
+ * HashSet.reduce(HashSet.make(0, 1, 2), 0, sum)
1929
+ * ```
449
1930
  */
450
1931
  export declare const reduce: {
451
1932
  /**
452
- * Reduces the specified state over the values of the `HashSet`.
1933
+ * @example
453
1934
  *
454
- * @since 2.0.0
455
- * @category folding
1935
+ * ```ts
1936
+ * import { HashSet, pipe } from "effect"
1937
+ * import * as assert from "node:assert/strict"
1938
+ *
1939
+ * assert.equal(
1940
+ * pipe(
1941
+ * HashSet.make(0, 1, 2),
1942
+ * HashSet.reduce(10, (accumulator, value) => accumulator + value)
1943
+ * ),
1944
+ * 13
1945
+ * )
1946
+ * ```
456
1947
  */
457
1948
  <A, Z>(zero: Z, f: (accumulator: Z, value: A) => Z): (self: HashSet<A>) => Z;
458
1949
  /**
459
- * Reduces the specified state over the values of the `HashSet`.
1950
+ * @example
1951
+ *
1952
+ * ```ts
1953
+ * import { HashSet } from "effect"
1954
+ * import * as assert from "node:assert/strict"
460
1955
  *
461
- * @since 2.0.0
462
- * @category folding
1956
+ * assert.equal(
1957
+ * HashSet.reduce(
1958
+ * HashSet.make(0, 1, 2),
1959
+ * -3,
1960
+ * (accumulator, value) => accumulator + value
1961
+ * ),
1962
+ * 0
1963
+ * )
1964
+ * ```
463
1965
  */
464
1966
  <A, Z>(self: HashSet<A>, zero: Z, f: (accumulator: Z, value: A) => Z): Z;
465
1967
  };
466
1968
  /**
467
1969
  * Filters values out of a `HashSet` using the specified predicate.
468
1970
  *
1971
+ * The time complexity is of **`O(n)`**.
1972
+ *
1973
+ * @memberof HashSet
469
1974
  * @since 2.0.0
470
1975
  * @category filtering
1976
+ * @example
1977
+ *
1978
+ * ```ts
1979
+ * // Syntax with Predicate
1980
+ * import { HashSet, type Predicate, pipe } from "effect"
1981
+ *
1982
+ * const filterPositiveNumbers: Predicate.Predicate<number> = (n) => n > 0
1983
+ *
1984
+ * // with `data-last`, a.k.a. `pipeable` API
1985
+ * pipe(
1986
+ * HashSet.make(-2, -1, 0, 1, 2),
1987
+ * HashSet.filter(filterPositiveNumbers)
1988
+ * )
1989
+ *
1990
+ * // or with the pipe method
1991
+ * HashSet.make(-2, -1, 0, 1, 2).pipe(HashSet.filter(filterPositiveNumbers))
1992
+ *
1993
+ * // or with `data-first` API
1994
+ * HashSet.filter(HashSet.make(-2, -1, 0, 1, 2), filterPositiveNumbers)
1995
+ * ```
1996
+ *
1997
+ * @example
1998
+ *
1999
+ * ```ts
2000
+ * /// Syntax with Refinement
2001
+ * import { HashSet, pipe } from "effect"
2002
+ *
2003
+ * const stringRefinement = (value: unknown): value is string =>
2004
+ * typeof value === "string"
2005
+ *
2006
+ * // with `data-last`, a.k.a. `pipeable` API
2007
+ * pipe(
2008
+ * HashSet.make(1, "unos", 2, "two", 3, "trois", 4, "vier"), // // HashSet.HashSet<number | string>
2009
+ * HashSet.filter(stringRefinement)
2010
+ * ) // HashSet.HashSet<string>
2011
+ *
2012
+ * // or with the pipe method
2013
+ * HashSet.make(1, "unos", 2, "two", 3, "trois", 4, "vier") // HashSet.HashSet<number | string>
2014
+ * .pipe(HashSet.filter(stringRefinement)) // HashSet.HashSet<string>
2015
+ *
2016
+ * // or with `data-first` API
2017
+ * HashSet.filter(
2018
+ * HashSet.make(1, "unos", 2, "two", 3, "trois", 4, "vier"), // HashSet.HashSet<number | string>
2019
+ * stringRefinement
2020
+ * ) // HashSet.HashSet<string>
2021
+ * ```
471
2022
  */
472
2023
  export declare const filter: {
473
2024
  /**
474
- * Filters values out of a `HashSet` using the specified predicate.
2025
+ * @example
475
2026
  *
476
- * @since 2.0.0
477
- * @category filtering
2027
+ * ```ts
2028
+ * import { HashSet, pipe, Predicate } from "effect"
2029
+ * import * as assert from "node:assert/strict"
2030
+ *
2031
+ * const numbersAndStringsHashSet: HashSet.HashSet<number | string> =
2032
+ * HashSet.make(1, "unos", 2, "two", 3, "trois", 4, "vier")
2033
+ *
2034
+ * const stringRefinement: Predicate.Refinement<
2035
+ * string | number,
2036
+ * string
2037
+ * > = (value) => typeof value === "string"
2038
+ *
2039
+ * const stringHashSet: HashSet.HashSet<string> = pipe(
2040
+ * numbersAndStringsHashSet,
2041
+ * HashSet.filter(stringRefinement)
2042
+ * )
2043
+ *
2044
+ * assert.equal(
2045
+ * pipe(stringHashSet, HashSet.every(Predicate.isString)),
2046
+ * true
2047
+ * )
2048
+ * ```
478
2049
  */
479
2050
  <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: HashSet<A>) => HashSet<B>;
480
2051
  /**
481
- * Filters values out of a `HashSet` using the specified predicate.
2052
+ * @example
2053
+ *
2054
+ * ```ts
2055
+ * import { HashSet, pipe, type Predicate } from "effect"
2056
+ * import * as assert from "node:assert/strict"
2057
+ *
2058
+ * const filterPositiveNumbers: Predicate.Predicate<number> = (n) => n > 0
482
2059
  *
483
- * @since 2.0.0
484
- * @category filtering
2060
+ * assert.deepStrictEqual(
2061
+ * pipe(
2062
+ * HashSet.make(-2, -1, 0, 1, 2),
2063
+ * HashSet.filter(filterPositiveNumbers)
2064
+ * ),
2065
+ * HashSet.make(1, 2)
2066
+ * )
2067
+ * ```
485
2068
  */
486
2069
  <A>(predicate: Predicate<NoInfer<A>>): (self: HashSet<A>) => HashSet<A>;
487
2070
  /**
488
- * Filters values out of a `HashSet` using the specified predicate.
2071
+ * @example
489
2072
  *
490
- * @since 2.0.0
491
- * @category filtering
2073
+ * ```ts
2074
+ * import { HashSet, Predicate } from "effect"
2075
+ * import * as assert from "node:assert/strict"
2076
+ *
2077
+ * const numbersAndStringsHashSet: HashSet.HashSet<number | string> =
2078
+ * HashSet.make(1, "unos", 2, "two", 3, "trois", 4, "vier")
2079
+ *
2080
+ * const stringRefinement: Predicate.Refinement<
2081
+ * string | number,
2082
+ * string
2083
+ * > = (value) => typeof value === "string"
2084
+ *
2085
+ * const stringHashSet: HashSet.HashSet<string> = HashSet.filter(
2086
+ * numbersAndStringsHashSet,
2087
+ * stringRefinement
2088
+ * )
2089
+ *
2090
+ * assert.equal(HashSet.every(stringHashSet, Predicate.isString), true)
2091
+ * ```
492
2092
  */
493
2093
  <A, B extends A>(self: HashSet<A>, refinement: Refinement<A, B>): HashSet<B>;
494
2094
  /**
495
- * Filters values out of a `HashSet` using the specified predicate.
2095
+ * @example
2096
+ *
2097
+ * ```ts
2098
+ * import { HashSet, pipe, type Predicate } from "effect"
2099
+ * import * as assert from "node:assert/strict"
496
2100
  *
497
- * @since 2.0.0
498
- * @category filtering
2101
+ * const filterPositiveNumbers: Predicate.Predicate<number> = (n) => n > 0
2102
+ *
2103
+ * assert.deepStrictEqual(
2104
+ * HashSet.filter(HashSet.make(-2, -1, 0, 1, 2), filterPositiveNumbers),
2105
+ * HashSet.make(1, 2)
2106
+ * )
2107
+ * ```
499
2108
  */
500
2109
  <A>(self: HashSet<A>, predicate: Predicate<A>): HashSet<A>;
501
2110
  };
@@ -506,52 +2115,155 @@ export declare const filter: {
506
2115
  * right side of the resulting `Tuple`, otherwise the value will be placed into
507
2116
  * the left side.
508
2117
  *
2118
+ * Time complexity is of **`O(n)`**.
2119
+ *
2120
+ * @memberof HashSet
509
2121
  * @since 2.0.0
510
2122
  * @category partitioning
2123
+ * @example
2124
+ *
2125
+ * ```ts
2126
+ * // Syntax with Predicate
2127
+ * import { HashSet, pipe, Predicate } from "effect"
2128
+ *
2129
+ * // with `data-last`, a.k.a. `pipeable` API
2130
+ * pipe(
2131
+ * HashSet.make(0, 1, 2, 3, 4, 5),
2132
+ * HashSet.partition((n) => n % 2 === 0)
2133
+ * )
2134
+ *
2135
+ * // or with the pipe method
2136
+ * HashSet.make(0, 1, 2, 3, 4, 5).pipe(
2137
+ * HashSet.partition((n) => n % 2 === 0)
2138
+ * )
2139
+ *
2140
+ * // or with `data-first` API
2141
+ * HashSet.partition(HashSet.make(0, 1, 2, 3, 4, 5), (n) => n % 2 === 0)
2142
+ * ```
2143
+ *
2144
+ * @example
2145
+ *
2146
+ * ```ts
2147
+ * // Syntax with Refinement
2148
+ * import { HashSet, pipe, Predicate } from "effect"
2149
+ *
2150
+ * const stringRefinement: Predicate.Refinement<string | number, string> = (
2151
+ * value
2152
+ * ) => typeof value === "string"
2153
+ *
2154
+ * // with `data-last`, a.k.a. `pipeable` API
2155
+ * pipe(
2156
+ * HashSet.make(1, "unos", 2, "two", 3, "trois", 4, "vier"),
2157
+ * HashSet.partition(stringRefinement)
2158
+ * )
2159
+ *
2160
+ * // or with the pipe method
2161
+ * HashSet.make(1, "unos", 2, "two", 3, "trois", 4, "vier").pipe(
2162
+ * HashSet.partition(stringRefinement)
2163
+ * )
2164
+ *
2165
+ * // or with `data-first` API
2166
+ * HashSet.partition(
2167
+ * HashSet.make(1, "unos", 2, "two", 3, "trois", 4, "vier"),
2168
+ * stringRefinement
2169
+ * )
2170
+ * ```
511
2171
  */
512
2172
  export declare const partition: {
513
2173
  /**
514
- * Partition the values of a `HashSet` using the specified predicate.
2174
+ * @example
2175
+ *
2176
+ * ```ts
2177
+ * import { HashSet, pipe, Predicate } from "effect"
2178
+ * import * as assert from "node:assert/strict"
2179
+ *
2180
+ * const numbersAndStringsHashSet: HashSet.HashSet<number | string> =
2181
+ * HashSet.make(1, "unos", 2, "two", 3, "trois", 4, "vier")
515
2182
  *
516
- * If a value matches the predicate, it will be placed into the `HashSet` on the
517
- * right side of the resulting `Tuple`, otherwise the value will be placed into
518
- * the left side.
2183
+ * const stringRefinement: Predicate.Refinement<
2184
+ * string | number,
2185
+ * string
2186
+ * > = (value) => typeof value === "string"
519
2187
  *
520
- * @since 2.0.0
521
- * @category partitioning
2188
+ * const [
2189
+ * excluded, // HashSet.HashSet<number>
2190
+ * satisfying // HashSet.HashSet<string>
2191
+ * ] = pipe(numbersAndStringsHashSet, HashSet.partition(stringRefinement))
2192
+ *
2193
+ * assert.equal(pipe(satisfying, HashSet.every(Predicate.isString)), true)
2194
+ * assert.equal(pipe(excluded, HashSet.every(Predicate.isNumber)), true)
2195
+ *
2196
+ * assert.deepStrictEqual(excluded, HashSet.make(1, 2, 3, 4))
2197
+ * assert.deepStrictEqual(
2198
+ * satisfying,
2199
+ * HashSet.make("unos", "two", "trois", "vier")
2200
+ * )
2201
+ * ```
522
2202
  */
523
2203
  <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: HashSet<A>) => [excluded: HashSet<Exclude<A, B>>, satisfying: HashSet<B>];
524
2204
  /**
525
- * Partition the values of a `HashSet` using the specified predicate.
2205
+ * @example
2206
+ *
2207
+ * ```ts
2208
+ * import { HashSet, pipe } from "effect"
2209
+ * import * as assert from "node:assert/strict"
526
2210
  *
527
- * If a value matches the predicate, it will be placed into the `HashSet` on the
528
- * right side of the resulting `Tuple`, otherwise the value will be placed into
529
- * the left side.
2211
+ * const [excluded, satisfying] = pipe(
2212
+ * HashSet.make(0, 1, 2, 3, 4, 5),
2213
+ * HashSet.partition((n) => n % 2 === 0)
2214
+ * )
530
2215
  *
531
- * @since 2.0.0
532
- * @category partitioning
2216
+ * assert.deepStrictEqual(excluded, HashSet.make(1, 3, 5))
2217
+ * assert.deepStrictEqual(satisfying, HashSet.make(0, 2, 4))
2218
+ * ```
533
2219
  */
534
2220
  <A>(predicate: Predicate<NoInfer<A>>): (self: HashSet<A>) => [excluded: HashSet<A>, satisfying: HashSet<A>];
535
2221
  /**
536
- * Partition the values of a `HashSet` using the specified predicate.
2222
+ * @example
537
2223
  *
538
- * If a value matches the predicate, it will be placed into the `HashSet` on the
539
- * right side of the resulting `Tuple`, otherwise the value will be placed into
540
- * the left side.
2224
+ * ```ts
2225
+ * import { HashSet, pipe, Predicate } from "effect"
2226
+ * import * as assert from "node:assert/strict"
541
2227
  *
542
- * @since 2.0.0
543
- * @category partitioning
2228
+ * const numbersAndStringsHashSet: HashSet.HashSet<number | string> =
2229
+ * HashSet.make(1, "unos", 2, "two", 3, "trois", 4, "vier")
2230
+ *
2231
+ * const stringRefinement: Predicate.Refinement<
2232
+ * string | number,
2233
+ * string
2234
+ * > = (value) => typeof value === "string"
2235
+ *
2236
+ * const [
2237
+ * excluded, // HashSet.HashSet<number>
2238
+ * satisfying // HashSet.HashSet<string>
2239
+ * ] = HashSet.partition(numbersAndStringsHashSet, stringRefinement)
2240
+ *
2241
+ * assert.equal(HashSet.every(satisfying, Predicate.isString), true)
2242
+ * assert.equal(HashSet.every(excluded, Predicate.isNumber), true)
2243
+ *
2244
+ * assert.deepStrictEqual(excluded, HashSet.make(1, 2, 3, 4))
2245
+ * assert.deepStrictEqual(
2246
+ * satisfying,
2247
+ * HashSet.make("unos", "two", "trois", "vier")
2248
+ * )
2249
+ * ```
544
2250
  */
545
2251
  <A, B extends A>(self: HashSet<A>, refinement: Refinement<A, B>): [excluded: HashSet<Exclude<A, B>>, satisfying: HashSet<B>];
546
2252
  /**
547
- * Partition the values of a `HashSet` using the specified predicate.
2253
+ * @example
2254
+ *
2255
+ * ```ts
2256
+ * import { HashSet } from "effect"
2257
+ * import * as assert from "node:assert/strict"
548
2258
  *
549
- * If a value matches the predicate, it will be placed into the `HashSet` on the
550
- * right side of the resulting `Tuple`, otherwise the value will be placed into
551
- * the left side.
2259
+ * const [excluded, satisfying] = HashSet.partition(
2260
+ * HashSet.make(0, 1, 2, 3, 4, 5),
2261
+ * (n) => n % 2 === 0
2262
+ * )
552
2263
  *
553
- * @since 2.0.0
554
- * @category partitioning
2264
+ * assert.deepStrictEqual(excluded, HashSet.make(1, 3, 5))
2265
+ * assert.deepStrictEqual(satisfying, HashSet.make(0, 2, 4))
2266
+ * ```
555
2267
  */
556
2268
  <A>(self: HashSet<A>, predicate: Predicate<A>): [excluded: HashSet<A>, satisfying: HashSet<A>];
557
2269
  };