@monstermann/set 0.2.0 → 0.4.0

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.
Files changed (66) hide show
  1. package/README.md +776 -0
  2. package/dist/Set/add.d.mts +12 -4
  3. package/dist/Set/add.mjs +12 -4
  4. package/dist/Set/addAll.d.mts +12 -4
  5. package/dist/Set/addAll.mjs +12 -4
  6. package/dist/Set/clone.d.mts +9 -4
  7. package/dist/Set/clone.mjs +9 -4
  8. package/dist/Set/compact.d.mts +11 -4
  9. package/dist/Set/compact.mjs +11 -4
  10. package/dist/Set/create.d.mts +9 -2
  11. package/dist/Set/create.mjs +9 -2
  12. package/dist/Set/difference.d.mts +12 -4
  13. package/dist/Set/difference.mjs +12 -4
  14. package/dist/Set/forEach.d.mts +15 -4
  15. package/dist/Set/forEach.mjs +15 -4
  16. package/dist/Set/has.d.mts +12 -4
  17. package/dist/Set/has.mjs +12 -4
  18. package/dist/Set/hasAll.d.mts +12 -4
  19. package/dist/Set/hasAll.mjs +12 -4
  20. package/dist/Set/hasAny.d.mts +12 -4
  21. package/dist/Set/hasAny.mjs +12 -4
  22. package/dist/Set/hasNone.d.mts +12 -4
  23. package/dist/Set/hasNone.mjs +12 -4
  24. package/dist/Set/index.d.mts +1 -7
  25. package/dist/Set/index.mjs +0 -12
  26. package/dist/Set/intersection.d.mts +12 -4
  27. package/dist/Set/intersection.mjs +12 -4
  28. package/dist/Set/is.d.mts +9 -4
  29. package/dist/Set/is.mjs +9 -4
  30. package/dist/Set/isDisjointFrom.d.mts +12 -4
  31. package/dist/Set/isDisjointFrom.mjs +12 -4
  32. package/dist/Set/isEmpty.d.mts +11 -4
  33. package/dist/Set/isEmpty.mjs +11 -4
  34. package/dist/Set/isShallowEqual.d.mts +12 -4
  35. package/dist/Set/isShallowEqual.mjs +12 -4
  36. package/dist/Set/isSubsetOf.d.mts +12 -4
  37. package/dist/Set/isSubsetOf.mjs +12 -4
  38. package/dist/Set/isSupersetOf.d.mts +12 -4
  39. package/dist/Set/isSupersetOf.mjs +12 -4
  40. package/dist/Set/mapEach.d.mts +15 -4
  41. package/dist/Set/mapEach.mjs +15 -4
  42. package/dist/Set/remove.d.mts +12 -4
  43. package/dist/Set/remove.mjs +12 -4
  44. package/dist/Set/removeAll.d.mts +12 -4
  45. package/dist/Set/removeAll.mjs +12 -4
  46. package/dist/Set/size.d.mts +11 -4
  47. package/dist/Set/size.mjs +11 -4
  48. package/dist/Set/symmetricDifference.d.mts +12 -4
  49. package/dist/Set/symmetricDifference.mjs +12 -4
  50. package/dist/Set/toArray.d.mts +9 -4
  51. package/dist/Set/toArray.mjs +9 -4
  52. package/dist/Set/union.d.mts +12 -4
  53. package/dist/Set/union.mjs +12 -4
  54. package/package.json +2 -2
  55. package/dist/Set/addOr.d.mts +0 -28
  56. package/dist/Set/addOr.mjs +0 -34
  57. package/dist/Set/addOrElse.d.mts +0 -35
  58. package/dist/Set/addOrElse.mjs +0 -41
  59. package/dist/Set/addOrThrow.d.mts +0 -28
  60. package/dist/Set/addOrThrow.mjs +0 -34
  61. package/dist/Set/removeOr.d.mts +0 -28
  62. package/dist/Set/removeOr.mjs +0 -34
  63. package/dist/Set/removeOrElse.d.mts +0 -35
  64. package/dist/Set/removeOrElse.mjs +0 -41
  65. package/dist/Set/removeOrThrow.d.mts +0 -28
  66. package/dist/Set/removeOrThrow.mjs +0 -34
package/README.md CHANGED
@@ -2,8 +2,784 @@
2
2
 
3
3
  <h1>set</h1>
4
4
 
5
+ ![Minified](https://img.shields.io/badge/Minified-3.43_KB-blue?style=flat-square&labelColor=%2315161D&color=%2369a1ff) ![Minzipped](https://img.shields.io/badge/Minzipped-1.03_KB-blue?style=flat-square&labelColor=%2315161D&color=%2369a1ff)
6
+
5
7
  **Functional utilities for sets.**
6
8
 
7
9
  [Documentation](https://MichaelOstermann.github.io/set)
8
10
 
9
11
  </div>
12
+
13
+ ## Features
14
+
15
+ - Opt-in mutability with [`remmi`](https://michaelostermann.github.io/remmi/)
16
+ - Reference preservation (`mapEach(set, (v) => v) === set`)
17
+ - Pipe-friendly (`pipe(mapEach((v) => v))(set)`)
18
+ - Graceful failure handling (`get()`, `getOr()`, `getOrElse()`, `getOrThrow()`)
19
+
20
+ ## Installation
21
+
22
+ ```sh [npm]
23
+ npm install @monstermann/set
24
+ ```
25
+
26
+ ```sh [pnpm]
27
+ pnpm add @monstermann/set
28
+ ```
29
+
30
+ ```sh [yarn]
31
+ yarn add @monstermann/set
32
+ ```
33
+
34
+ ```sh [bun]
35
+ bun add @monstermann/set
36
+ ```
37
+
38
+ ## Tree-shaking
39
+
40
+ ### Installation
41
+
42
+ ```sh [npm]
43
+ npm install -D @monstermann/unplugin-set
44
+ ```
45
+
46
+ ```sh [pnpm]
47
+ pnpm -D add @monstermann/unplugin-set
48
+ ```
49
+
50
+ ```sh [yarn]
51
+ yarn -D add @monstermann/unplugin-set
52
+ ```
53
+
54
+ ```sh [bun]
55
+ bun -D add @monstermann/unplugin-set
56
+ ```
57
+
58
+ ### Usage
59
+
60
+ ```ts [Vite]
61
+ // vite.config.ts
62
+ import set from "@monstermann/unplugin-set/vite";
63
+
64
+ export default defineConfig({
65
+ plugins: [set()],
66
+ });
67
+ ```
68
+
69
+ ```ts [Rollup]
70
+ // rollup.config.js
71
+ import set from "@monstermann/unplugin-set/rollup";
72
+
73
+ export default {
74
+ plugins: [set()],
75
+ };
76
+ ```
77
+
78
+ ```ts [Rolldown]
79
+ // rolldown.config.js
80
+ import set from "@monstermann/unplugin-set/rolldown";
81
+
82
+ export default {
83
+ plugins: [set()],
84
+ };
85
+ ```
86
+
87
+ ```ts [Webpack]
88
+ // webpack.config.js
89
+ const set = require("@monstermann/unplugin-set/webpack");
90
+
91
+ module.exports = {
92
+ plugins: [set()],
93
+ };
94
+ ```
95
+
96
+ ```ts [Rspack]
97
+ // rspack.config.js
98
+ const set = require("@monstermann/unplugin-set/rspack");
99
+
100
+ module.exports = {
101
+ plugins: [set()],
102
+ };
103
+ ```
104
+
105
+ ```ts [ESBuild]
106
+ // esbuild.config.js
107
+ import { build } from "esbuild";
108
+ import set from "@monstermann/unplugin-set/esbuild";
109
+
110
+ build({
111
+ plugins: [set()],
112
+ });
113
+ ```
114
+
115
+ ## Set
116
+
117
+ ### add
118
+
119
+ ```ts
120
+ function Set.add<T>(
121
+ target: ReadonlySet<T>,
122
+ value: NoInfer<T>,
123
+ ): ReadonlySet<T>
124
+ ```
125
+
126
+ Returns a set with the value added. If the value already exists in the set, returns the original set unchanged.
127
+
128
+ #### Example
129
+
130
+ ```ts [data-first]
131
+ import { Set } from "@monstermann/set";
132
+
133
+ Set.add(Set.create([1, 2]), 3); // Set([1, 2, 3])
134
+ Set.add(Set.create([1, 2]), 2); // Set([1, 2])
135
+ ```
136
+
137
+ ```ts [data-last]
138
+ import { Set } from "@monstermann/set";
139
+
140
+ pipe(Set.create([1, 2]), Set.add(3)); // Set([1, 2, 3])
141
+ pipe(Set.create([1, 2]), Set.add(2)); // Set([1, 2])
142
+ ```
143
+
144
+ ### addAll
145
+
146
+ ```ts
147
+ function Set.addAll<T>(
148
+ target: ReadonlySet<T>,
149
+ values: Iterable<NoInfer<T>>,
150
+ ): ReadonlySet<T>
151
+ ```
152
+
153
+ Returns a set with all values from the iterable added. Values that already exist in the set are skipped.
154
+
155
+ #### Example
156
+
157
+ ```ts [data-first]
158
+ import { Set } from "@monstermann/set";
159
+
160
+ Set.addAll(Set.create([1, 2]), [3, 4]); // Set([1, 2, 3, 4])
161
+ Set.addAll(Set.create([1, 2]), [2, 3]); // Set([1, 2, 3])
162
+ ```
163
+
164
+ ```ts [data-last]
165
+ import { Set } from "@monstermann/set";
166
+
167
+ pipe(Set.create([1, 2]), Set.addAll([3, 4])); // Set([1, 2, 3, 4])
168
+ pipe(Set.create([1, 2]), Set.addAll([2, 3])); // Set([1, 2, 3])
169
+ ```
170
+
171
+ ### clone
172
+
173
+ ```ts
174
+ function Set.clone<T>(target: ReadonlySet<T>): Set<T>
175
+ ```
176
+
177
+ Returns a shallow copy of the set, unless marked as mutable with `markAsMutable` inside a mutation context (see [@monstermann/remmi](https://michaelostermann.github.io/remmi/#clonearray-array)).
178
+
179
+ #### Example
180
+
181
+ ```ts [data-first]
182
+ import { Set } from "@monstermann/set";
183
+
184
+ const original = Set.create([1, 2, 3]);
185
+ const copy = Set.clone(original); // Set { 1, 2, 3 }
186
+ ```
187
+
188
+ ```ts [data-last]
189
+ import { Set } from "@monstermann/set";
190
+
191
+ const original = Set.create([1, 2, 3]);
192
+ const copy = pipe(original, Set.clone()); // Set { 1, 2, 3 }
193
+ ```
194
+
195
+ ### compact
196
+
197
+ ```ts
198
+ function Set.compact<T>(
199
+ target: ReadonlySet<T>,
200
+ ): ReadonlySet<NonNil<T>>
201
+ ```
202
+
203
+ Returns a set with all `null` and `undefined` values removed.
204
+
205
+ #### Example
206
+
207
+ ```ts [data-first]
208
+ import { Set } from "@monstermann/set";
209
+
210
+ Set.compact(Set.create([1, null, 2, undefined])); // Set([1, 2])
211
+ Set.compact(Set.create([1, 2, 3])); // Set([1, 2, 3])
212
+ ```
213
+
214
+ ```ts [data-last]
215
+ import { Set } from "@monstermann/set";
216
+
217
+ pipe(Set.create([1, null, 2, undefined]), Set.compact()); // Set([1, 2])
218
+ pipe(Set.create([1, 2, 3]), Set.compact()); // Set([1, 2, 3])
219
+ ```
220
+
221
+ ### create
222
+
223
+ ```ts
224
+ function Set.create<T>(
225
+ iterable?: Iterable<T> | null | undefined,
226
+ ): Set<T>
227
+ ```
228
+
229
+ Creates a new set from an optional iterable.
230
+
231
+ #### Example
232
+
233
+ ```ts
234
+ import { Set } from "@monstermann/set";
235
+
236
+ Set.create([1, 2, 3]); // Set([1, 2, 3])
237
+ ```
238
+
239
+ ### difference
240
+
241
+ ```ts
242
+ function Set.difference<T, U>(
243
+ target: Set<T>,
244
+ source: Set<U>,
245
+ ): Set<T>
246
+ ```
247
+
248
+ Returns a set containing all values from the target set that are not in the source set.
249
+
250
+ #### Example
251
+
252
+ ```ts [data-first]
253
+ import { Set } from "@monstermann/set";
254
+
255
+ Set.difference(Set.create([1, 2, 3]), Set.create([2, 3, 4])); // Set([1])
256
+ Set.difference(Set.create([1, 2]), Set.create([3, 4])); // Set([1, 2])
257
+ ```
258
+
259
+ ```ts [data-last]
260
+ import { Set } from "@monstermann/set";
261
+
262
+ pipe(Set.create([1, 2, 3]), Set.difference(Set.create([2, 3, 4]))); // Set([1])
263
+ pipe(Set.create([1, 2]), Set.difference(Set.create([3, 4]))); // Set([1, 2])
264
+ ```
265
+
266
+ ### forEach
267
+
268
+ ```ts
269
+ function Set.forEach<T>(
270
+ target: ReadonlySet<T>,
271
+ fn: (
272
+ value: NoInfer<T>,
273
+ target: ReadonlySet<NoInfer<T>>,
274
+ ) => unknown,
275
+ ): ReadonlySet<T>
276
+ ```
277
+
278
+ Executes a function for each value in the set and returns the set unchanged.
279
+
280
+ #### Example
281
+
282
+ ```ts [data-first]
283
+ import { Set } from "@monstermann/set";
284
+
285
+ Set.forEach(Set.create([1, 2, 3]), (value) => console.log(value)); // Set([1, 2, 3])
286
+ ```
287
+
288
+ ```ts [data-last]
289
+ import { Set } from "@monstermann/set";
290
+
291
+ pipe(
292
+ Set.create([1, 2, 3]),
293
+ Set.forEach((value) => console.log(value)),
294
+ ); // Set([1, 2, 3])
295
+ ```
296
+
297
+ ### has
298
+
299
+ ```ts
300
+ function Set.has<T>(
301
+ target: ReadonlySet<T>,
302
+ value: NoInfer<T>,
303
+ ): boolean
304
+ ```
305
+
306
+ Returns `true` if the set contains the value, `false` otherwise.
307
+
308
+ #### Example
309
+
310
+ ```ts [data-first]
311
+ import { Set } from "@monstermann/set";
312
+
313
+ Set.has(Set.create([1, 2, 3]), 2); // true
314
+ Set.has(Set.create([1, 2, 3]), 4); // false
315
+ ```
316
+
317
+ ```ts [data-last]
318
+ import { Set } from "@monstermann/set";
319
+
320
+ pipe(Set.create([1, 2, 3]), Set.has(2)); // true
321
+ pipe(Set.create([1, 2, 3]), Set.has(4)); // false
322
+ ```
323
+
324
+ ### hasAll
325
+
326
+ ```ts
327
+ function Set.hasAll<T>(
328
+ target: ReadonlySet<T>,
329
+ values: Iterable<NoInfer<T>>,
330
+ ): boolean
331
+ ```
332
+
333
+ Returns `true` if the set contains all values from the iterable, `false` otherwise.
334
+
335
+ #### Example
336
+
337
+ ```ts [data-first]
338
+ import { Set } from "@monstermann/set";
339
+
340
+ Set.hasAll(Set.create([1, 2, 3]), [1, 2]); // true
341
+ Set.hasAll(Set.create([1, 2, 3]), [1, 4]); // false
342
+ ```
343
+
344
+ ```ts [data-last]
345
+ import { Set } from "@monstermann/set";
346
+
347
+ pipe(Set.create([1, 2, 3]), Set.hasAll([1, 2])); // true
348
+ pipe(Set.create([1, 2, 3]), Set.hasAll([1, 4])); // false
349
+ ```
350
+
351
+ ### hasAny
352
+
353
+ ```ts
354
+ function Set.hasAny<T>(
355
+ target: ReadonlySet<T>,
356
+ values: Iterable<NoInfer<T>>,
357
+ ): boolean
358
+ ```
359
+
360
+ Returns `true` if the set contains at least one value from the iterable, `false` otherwise.
361
+
362
+ #### Example
363
+
364
+ ```ts [data-first]
365
+ import { Set } from "@monstermann/set";
366
+
367
+ Set.hasAny(Set.create([1, 2, 3]), [3, 4]); // true
368
+ Set.hasAny(Set.create([1, 2, 3]), [4, 5]); // false
369
+ ```
370
+
371
+ ```ts [data-last]
372
+ import { Set } from "@monstermann/set";
373
+
374
+ pipe(Set.create([1, 2, 3]), Set.hasAny([3, 4])); // true
375
+ pipe(Set.create([1, 2, 3]), Set.hasAny([4, 5])); // false
376
+ ```
377
+
378
+ ### hasNone
379
+
380
+ ```ts
381
+ function Set.hasNone<T>(
382
+ target: ReadonlySet<T>,
383
+ values: Iterable<NoInfer<T>>,
384
+ ): boolean
385
+ ```
386
+
387
+ Returns `true` if the set contains none of the values from the iterable, `false` otherwise.
388
+
389
+ #### Example
390
+
391
+ ```ts [data-first]
392
+ import { Set } from "@monstermann/set";
393
+
394
+ Set.hasNone(Set.create([1, 2, 3]), [4, 5]); // true
395
+ Set.hasNone(Set.create([1, 2, 3]), [3, 4]); // false
396
+ ```
397
+
398
+ ```ts [data-last]
399
+ import { Set } from "@monstermann/set";
400
+
401
+ pipe(Set.create([1, 2, 3]), Set.hasNone([4, 5])); // true
402
+ pipe(Set.create([1, 2, 3]), Set.hasNone([3, 4])); // false
403
+ ```
404
+
405
+ ### intersection
406
+
407
+ ```ts
408
+ function Set.intersection<T, U>(
409
+ target: Set<T>,
410
+ source: Set<U>,
411
+ ): Set<T | U>
412
+ ```
413
+
414
+ Returns a set containing only the values that exist in both sets.
415
+
416
+ #### Example
417
+
418
+ ```ts [data-first]
419
+ import { Set } from "@monstermann/set";
420
+
421
+ Set.intersection(Set.create([1, 2, 3]), Set.create([2, 3, 4])); // Set([2, 3])
422
+ Set.intersection(Set.create([1, 2]), Set.create([3, 4])); // Set([])
423
+ ```
424
+
425
+ ```ts [data-last]
426
+ import { Set } from "@monstermann/set";
427
+
428
+ pipe(Set.create([1, 2, 3]), Set.intersection(Set.create([2, 3, 4]))); // Set([2, 3])
429
+ pipe(Set.create([1, 2]), Set.intersection(Set.create([3, 4]))); // Set([])
430
+ ```
431
+
432
+ ### is
433
+
434
+ ```ts
435
+ function Set.is(target: unknown): target is Set<unknown>
436
+ ```
437
+
438
+ Returns `true` if the value is a Set, `false` otherwise.
439
+
440
+ #### Example
441
+
442
+ ```ts [data-first]
443
+ import { Set } from "@monstermann/set";
444
+
445
+ Set.is(Set.create([1, 2, 3])); // true
446
+ Set.is([1, 2, 3]); // false
447
+ Set.is({}); // false
448
+ ```
449
+
450
+ ```ts [data-last]
451
+ import { Set } from "@monstermann/set";
452
+
453
+ pipe(Set.create([1, 2, 3]), Set.is()); // true
454
+ pipe([1, 2, 3], Set.is()); // false
455
+ pipe({}, Set.is()); // false
456
+ ```
457
+
458
+ ### isDisjointFrom
459
+
460
+ ```ts
461
+ function Set.isDisjointFrom<T>(
462
+ target: ReadonlySet<T>,
463
+ source: ReadonlySet<NoInfer<T>>,
464
+ ): boolean
465
+ ```
466
+
467
+ Returns `true` if the sets have no values in common, `false` otherwise.
468
+
469
+ #### Example
470
+
471
+ ```ts [data-first]
472
+ import { Set } from "@monstermann/set";
473
+
474
+ Set.isDisjointFrom(Set.create([1, 2]), Set.create([3, 4])); // true
475
+ Set.isDisjointFrom(Set.create([1, 2]), Set.create([2, 3])); // false
476
+ ```
477
+
478
+ ```ts [data-last]
479
+ import { Set } from "@monstermann/set";
480
+
481
+ pipe(Set.create([1, 2]), Set.isDisjointFrom(Set.create([3, 4]))); // true
482
+ pipe(Set.create([1, 2]), Set.isDisjointFrom(Set.create([2, 3]))); // false
483
+ ```
484
+
485
+ ### isEmpty
486
+
487
+ ```ts
488
+ function Set.isEmpty<T extends ReadonlySet<unknown>>(
489
+ target: T,
490
+ ): boolean
491
+ ```
492
+
493
+ Returns `true` if the set contains no values, `false` otherwise.
494
+
495
+ #### Example
496
+
497
+ ```ts [data-first]
498
+ import { Set } from "@monstermann/set";
499
+
500
+ Set.isEmpty(Set.create()); // true
501
+ Set.isEmpty(Set.create([1, 2, 3])); // false
502
+ ```
503
+
504
+ ```ts [data-last]
505
+ import { Set } from "@monstermann/set";
506
+
507
+ pipe(Set.create(), Set.isEmpty()); // true
508
+ pipe(Set.create([1, 2, 3]), Set.isEmpty()); // false
509
+ ```
510
+
511
+ ### isShallowEqual
512
+
513
+ ```ts
514
+ function Set.isShallowEqual<T>(
515
+ target: ReadonlySet<T>,
516
+ source: ReadonlySet<NoInfer<T>>,
517
+ ): boolean
518
+ ```
519
+
520
+ Returns `true` if both sets contain the same values, `false` otherwise.
521
+
522
+ #### Example
523
+
524
+ ```ts [data-first]
525
+ import { Set } from "@monstermann/set";
526
+
527
+ Set.isShallowEqual(Set.create([1, 2, 3]), Set.create([3, 2, 1])); // true
528
+ Set.isShallowEqual(Set.create([1, 2]), Set.create([1, 2, 3])); // false
529
+ ```
530
+
531
+ ```ts [data-last]
532
+ import { Set } from "@monstermann/set";
533
+
534
+ pipe(Set.create([1, 2, 3]), Set.isShallowEqual(Set.create([3, 2, 1]))); // true
535
+ pipe(Set.create([1, 2]), Set.isShallowEqual(Set.create([1, 2, 3]))); // false
536
+ ```
537
+
538
+ ### isSubsetOf
539
+
540
+ ```ts
541
+ function Set.isSubsetOf<T>(
542
+ target: ReadonlySet<T>,
543
+ source: ReadonlySet<NoInfer<T>>,
544
+ ): boolean
545
+ ```
546
+
547
+ Returns `true` if all values in the target set are also in the source set, `false` otherwise.
548
+
549
+ #### Example
550
+
551
+ ```ts [data-first]
552
+ import { Set } from "@monstermann/set";
553
+
554
+ Set.isSubsetOf(Set.create([1, 2]), Set.create([1, 2, 3])); // true
555
+ Set.isSubsetOf(Set.create([1, 4]), Set.create([1, 2, 3])); // false
556
+ ```
557
+
558
+ ```ts [data-last]
559
+ import { Set } from "@monstermann/set";
560
+
561
+ pipe(Set.create([1, 2]), Set.isSubsetOf(Set.create([1, 2, 3]))); // true
562
+ pipe(Set.create([1, 4]), Set.isSubsetOf(Set.create([1, 2, 3]))); // false
563
+ ```
564
+
565
+ ### isSupersetOf
566
+
567
+ ```ts
568
+ function Set.isSupersetOf<T>(
569
+ target: ReadonlySet<T>,
570
+ source: ReadonlySet<NoInfer<T>>,
571
+ ): boolean
572
+ ```
573
+
574
+ Returns `true` if the target set contains all values from the source set, `false` otherwise.
575
+
576
+ #### Example
577
+
578
+ ```ts [data-first]
579
+ import { Set } from "@monstermann/set";
580
+
581
+ Set.isSupersetOf(Set.create([1, 2, 3]), Set.create([1, 2])); // true
582
+ Set.isSupersetOf(Set.create([1, 2, 3]), Set.create([1, 4])); // false
583
+ ```
584
+
585
+ ```ts [data-last]
586
+ import { Set } from "@monstermann/set";
587
+
588
+ pipe(Set.create([1, 2, 3]), Set.isSupersetOf(Set.create([1, 2]))); // true
589
+ pipe(Set.create([1, 2, 3]), Set.isSupersetOf(Set.create([1, 4]))); // false
590
+ ```
591
+
592
+ ### mapEach
593
+
594
+ ```ts
595
+ function Set.mapEach<T, U>(
596
+ target: ReadonlySet<T>,
597
+ fn: (
598
+ value: NoInfer<T>,
599
+ target: ReadonlySet<NoInfer<T>>,
600
+ ) => U,
601
+ ): ReadonlySet<U>
602
+ ```
603
+
604
+ Returns a new set with each value transformed by the mapping function.
605
+
606
+ #### Example
607
+
608
+ ```ts [data-first]
609
+ import { Set } from "@monstermann/set";
610
+
611
+ Set.mapEach(Set.create([1, 2, 3]), (x) => x * 2); // Set([2, 4, 6])
612
+ Set.mapEach(Set.create(["a", "b"]), (x) => x.toUpperCase()); // Set(['A', 'B'])
613
+ ```
614
+
615
+ ```ts [data-last]
616
+ import { Set } from "@monstermann/set";
617
+
618
+ pipe(
619
+ Set.create([1, 2, 3]),
620
+ Set.mapEach((x) => x * 2),
621
+ ); // Set([2, 4, 6])
622
+
623
+ pipe(
624
+ Set.create(["a", "b"]),
625
+ Set.mapEach((x) => x.toUpperCase()),
626
+ ); // Set(['A', 'B'])
627
+ ```
628
+
629
+ ### remove
630
+
631
+ ```ts
632
+ function Set.remove<T>(
633
+ target: ReadonlySet<T>,
634
+ value: NoInfer<T>,
635
+ ): ReadonlySet<T>
636
+ ```
637
+
638
+ Returns a set with the value removed. If the value doesn't exist in the set, returns the original set unchanged.
639
+
640
+ #### Example
641
+
642
+ ```ts [data-first]
643
+ import { Set } from "@monstermann/set";
644
+
645
+ Set.remove(Set.create([1, 2, 3]), 2); // Set([1, 3])
646
+ Set.remove(Set.create([1, 2, 3]), 4); // Set([1, 2, 3])
647
+ ```
648
+
649
+ ```ts [data-last]
650
+ import { Set } from "@monstermann/set";
651
+
652
+ pipe(Set.create([1, 2, 3]), Set.remove(2)); // Set([1, 3])
653
+ pipe(Set.create([1, 2, 3]), Set.remove(4)); // Set([1, 2, 3])
654
+ ```
655
+
656
+ ### removeAll
657
+
658
+ ```ts
659
+ function Set.removeAll<T>(
660
+ target: ReadonlySet<T>,
661
+ values: Iterable<NoInfer<T>>,
662
+ ): ReadonlySet<T>
663
+ ```
664
+
665
+ Returns a set with all values from the iterable removed. Values that don't exist in the set are skipped.
666
+
667
+ #### Example
668
+
669
+ ```ts [data-first]
670
+ import { Set } from "@monstermann/set";
671
+
672
+ Set.removeAll(Set.create([1, 2, 3, 4]), [2, 3]); // Set([1, 4])
673
+ Set.removeAll(Set.create([1, 2, 3]), [4, 5]); // Set([1, 2, 3])
674
+ ```
675
+
676
+ ```ts [data-last]
677
+ import { Set } from "@monstermann/set";
678
+
679
+ pipe(Set.create([1, 2, 3, 4]), Set.removeAll([2, 3])); // Set([1, 4])
680
+ pipe(Set.create([1, 2, 3]), Set.removeAll([4, 5])); // Set([1, 2, 3])
681
+ ```
682
+
683
+ ### size
684
+
685
+ ```ts
686
+ function Set.size<T extends ReadonlySet<unknown>>(
687
+ target: T,
688
+ ): number
689
+ ```
690
+
691
+ Returns the number of values in the set.
692
+
693
+ #### Example
694
+
695
+ ```ts [data-first]
696
+ import { Set } from "@monstermann/set";
697
+
698
+ Set.size(Set.create([1, 2, 3])); // 3
699
+ Set.size(Set.create()); // 0
700
+ ```
701
+
702
+ ```ts [data-last]
703
+ import { Set } from "@monstermann/set";
704
+
705
+ pipe(Set.create([1, 2, 3]), Set.size()); // 3
706
+ pipe(Set.create(), Set.size()); // 0
707
+ ```
708
+
709
+ ### symmetricDifference
710
+
711
+ ```ts
712
+ function Set.symmetricDifference<T, U>(
713
+ target: Set<T>,
714
+ source: Set<U>,
715
+ ): Set<T | U>
716
+ ```
717
+
718
+ Returns a set containing values that exist in either set but not in both.
719
+
720
+ #### Example
721
+
722
+ ```ts [data-first]
723
+ import { Set } from "@monstermann/set";
724
+
725
+ Set.symmetricDifference(Set.create([1, 2, 3]), Set.create([3, 4, 5])); // Set([1, 2, 4, 5])
726
+ Set.symmetricDifference(Set.create([1, 2]), Set.create([3, 4])); // Set([1, 2, 3, 4])
727
+ ```
728
+
729
+ ```ts [data-last]
730
+ import { Set } from "@monstermann/set";
731
+
732
+ pipe(Set.create([1, 2, 3]), Set.symmetricDifference(Set.create([3, 4, 5]))); // Set([1, 2, 4, 5])
733
+ pipe(Set.create([1, 2]), Set.symmetricDifference(Set.create([3, 4]))); // Set([1, 2, 3, 4])
734
+ ```
735
+
736
+ ### toArray
737
+
738
+ ```ts
739
+ function Set.toArray<T>(target: ReadonlySet<T>): T[]
740
+ ```
741
+
742
+ Converts the set to an array.
743
+
744
+ #### Example
745
+
746
+ ```ts [data-first]
747
+ import { Set } from "@monstermann/set";
748
+
749
+ Set.toArray(Set.create([1, 2, 3])); // [1, 2, 3]
750
+ Set.toArray(Set.create(["a", "b"])); // ['a', 'b']
751
+ ```
752
+
753
+ ```ts [data-last]
754
+ import { Set } from "@monstermann/set";
755
+
756
+ pipe(Set.create([1, 2, 3]), Set.toArray()); // [1, 2, 3]
757
+ pipe(Set.create(["a", "b"]), Set.toArray()); // ['a', 'b']
758
+ ```
759
+
760
+ ### union
761
+
762
+ ```ts
763
+ function Set.union<T, U>(
764
+ target: Set<T>,
765
+ source: Set<U>,
766
+ ): Set<T | U>
767
+ ```
768
+
769
+ Returns a set containing all values from both sets.
770
+
771
+ #### Example
772
+
773
+ ```ts [data-first]
774
+ import { Set } from "@monstermann/set";
775
+
776
+ Set.union(Set.create([1, 2]), Set.create([2, 3, 4])); // Set([1, 2, 3, 4])
777
+ Set.union(Set.create([1, 2]), Set.create([3, 4])); // Set([1, 2, 3, 4])
778
+ ```
779
+
780
+ ```ts [data-last]
781
+ import { Set } from "@monstermann/set";
782
+
783
+ pipe(Set.create([1, 2]), Set.union(Set.create([2, 3, 4]))); // Set([1, 2, 3, 4])
784
+ pipe(Set.create([1, 2]), Set.union(Set.create([3, 4]))); // Set([1, 2, 3, 4])
785
+ ```