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