@monstermann/set 0.1.1 → 0.3.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.
- package/README.md +776 -0
- package/dist/Set/add.d.mts +12 -4
- package/dist/Set/add.mjs +12 -4
- package/dist/Set/addAll.d.mts +12 -4
- package/dist/Set/addAll.mjs +12 -4
- package/dist/Set/clone.d.mts +9 -4
- package/dist/Set/clone.mjs +9 -4
- package/dist/Set/compact.d.mts +11 -4
- package/dist/Set/compact.mjs +11 -4
- package/dist/Set/create.d.mts +9 -2
- package/dist/Set/create.mjs +9 -2
- package/dist/Set/difference.d.mts +12 -4
- package/dist/Set/difference.mjs +17 -13
- package/dist/Set/forEach.d.mts +15 -4
- package/dist/Set/forEach.mjs +15 -4
- package/dist/Set/has.d.mts +12 -4
- package/dist/Set/has.mjs +12 -4
- package/dist/Set/hasAll.d.mts +12 -4
- package/dist/Set/hasAll.mjs +12 -4
- package/dist/Set/hasAny.d.mts +12 -4
- package/dist/Set/hasAny.mjs +12 -4
- package/dist/Set/hasNone.d.mts +12 -4
- package/dist/Set/hasNone.mjs +12 -4
- package/dist/Set/index.d.mts +1 -7
- package/dist/Set/index.mjs +0 -12
- package/dist/Set/intersection.d.mts +12 -4
- package/dist/Set/intersection.mjs +17 -13
- package/dist/Set/is.d.mts +9 -4
- package/dist/Set/is.mjs +9 -4
- package/dist/Set/isDisjointFrom.d.mts +12 -4
- package/dist/Set/isDisjointFrom.mjs +12 -4
- package/dist/Set/isEmpty.d.mts +11 -4
- package/dist/Set/isEmpty.mjs +11 -4
- package/dist/Set/isShallowEqual.d.mts +12 -4
- package/dist/Set/isShallowEqual.mjs +12 -4
- package/dist/Set/isSubsetOf.d.mts +12 -4
- package/dist/Set/isSubsetOf.mjs +12 -4
- package/dist/Set/isSupersetOf.d.mts +12 -4
- package/dist/Set/isSupersetOf.mjs +12 -4
- package/dist/Set/mapEach.d.mts +15 -4
- package/dist/Set/mapEach.mjs +15 -4
- package/dist/Set/remove.d.mts +12 -4
- package/dist/Set/remove.mjs +12 -4
- package/dist/Set/removeAll.d.mts +12 -4
- package/dist/Set/removeAll.mjs +12 -4
- package/dist/Set/size.d.mts +11 -4
- package/dist/Set/size.mjs +11 -4
- package/dist/Set/symmetricDifference.d.mts +12 -4
- package/dist/Set/symmetricDifference.mjs +22 -16
- package/dist/Set/toArray.d.mts +9 -4
- package/dist/Set/toArray.mjs +9 -4
- package/dist/Set/union.d.mts +12 -4
- package/dist/Set/union.mjs +19 -9
- package/package.json +2 -2
- package/dist/Set/addOr.d.mts +0 -28
- package/dist/Set/addOr.mjs +0 -34
- package/dist/Set/addOrElse.d.mts +0 -35
- package/dist/Set/addOrElse.mjs +0 -41
- package/dist/Set/addOrThrow.d.mts +0 -28
- package/dist/Set/addOrThrow.mjs +0 -34
- package/dist/Set/removeOr.d.mts +0 -28
- package/dist/Set/removeOr.mjs +0 -34
- package/dist/Set/removeOrElse.d.mts +0 -35
- package/dist/Set/removeOrElse.mjs +0 -41
- package/dist/Set/removeOrThrow.d.mts +0 -28
- package/dist/Set/removeOrThrow.mjs +0 -34
package/dist/Set/isSubsetOf.mjs
CHANGED
|
@@ -2,25 +2,33 @@ import { dfdlT } from "@monstermann/dfdl";
|
|
|
2
2
|
|
|
3
3
|
//#region src/Set/isSubsetOf.ts
|
|
4
4
|
/**
|
|
5
|
+
* # isSubsetOf
|
|
6
|
+
*
|
|
5
7
|
* ```ts
|
|
6
|
-
* function Set.isSubsetOf(
|
|
8
|
+
* function Set.isSubsetOf<T>(
|
|
9
|
+
* target: ReadonlySet<T>,
|
|
10
|
+
* source: ReadonlySet<NoInfer<T>>,
|
|
11
|
+
* ): boolean
|
|
7
12
|
* ```
|
|
8
13
|
*
|
|
9
|
-
*
|
|
14
|
+
* Returns `true` if all values in the target set are also in the source set, `false` otherwise.
|
|
10
15
|
*
|
|
11
|
-
*
|
|
16
|
+
* ## Example
|
|
17
|
+
*
|
|
18
|
+
* ```ts [data-first]
|
|
12
19
|
* import { Set } from "@monstermann/set";
|
|
13
20
|
*
|
|
14
21
|
* Set.isSubsetOf(Set.create([1, 2]), Set.create([1, 2, 3])); // true
|
|
15
22
|
* Set.isSubsetOf(Set.create([1, 4]), Set.create([1, 2, 3])); // false
|
|
16
23
|
* ```
|
|
17
24
|
*
|
|
18
|
-
* ```ts
|
|
25
|
+
* ```ts [data-last]
|
|
19
26
|
* import { Set } from "@monstermann/set";
|
|
20
27
|
*
|
|
21
28
|
* pipe(Set.create([1, 2]), Set.isSubsetOf(Set.create([1, 2, 3]))); // true
|
|
22
29
|
* pipe(Set.create([1, 4]), Set.isSubsetOf(Set.create([1, 2, 3]))); // false
|
|
23
30
|
* ```
|
|
31
|
+
*
|
|
24
32
|
*/
|
|
25
33
|
const isSubsetOf = dfdlT((target, source) => {
|
|
26
34
|
if (target.size > source.size) return false;
|
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
//#region src/Set/isSupersetOf.d.ts
|
|
2
2
|
/**
|
|
3
|
+
* # isSupersetOf
|
|
4
|
+
*
|
|
3
5
|
* ```ts
|
|
4
|
-
* function Set.isSupersetOf(
|
|
6
|
+
* function Set.isSupersetOf<T>(
|
|
7
|
+
* target: ReadonlySet<T>,
|
|
8
|
+
* source: ReadonlySet<NoInfer<T>>,
|
|
9
|
+
* ): boolean
|
|
5
10
|
* ```
|
|
6
11
|
*
|
|
7
|
-
*
|
|
12
|
+
* Returns `true` if the target set contains all values from the source set, `false` otherwise.
|
|
8
13
|
*
|
|
9
|
-
*
|
|
14
|
+
* ## Example
|
|
15
|
+
*
|
|
16
|
+
* ```ts [data-first]
|
|
10
17
|
* import { Set } from "@monstermann/set";
|
|
11
18
|
*
|
|
12
19
|
* Set.isSupersetOf(Set.create([1, 2, 3]), Set.create([1, 2])); // true
|
|
13
20
|
* Set.isSupersetOf(Set.create([1, 2, 3]), Set.create([1, 4])); // false
|
|
14
21
|
* ```
|
|
15
22
|
*
|
|
16
|
-
* ```ts
|
|
23
|
+
* ```ts [data-last]
|
|
17
24
|
* import { Set } from "@monstermann/set";
|
|
18
25
|
*
|
|
19
26
|
* pipe(Set.create([1, 2, 3]), Set.isSupersetOf(Set.create([1, 2]))); // true
|
|
20
27
|
* pipe(Set.create([1, 2, 3]), Set.isSupersetOf(Set.create([1, 4]))); // false
|
|
21
28
|
* ```
|
|
29
|
+
*
|
|
22
30
|
*/
|
|
23
31
|
declare const isSupersetOf: {
|
|
24
32
|
<T>(source: ReadonlySet<NoInfer<T>>): (target: ReadonlySet<T>) => boolean;
|
|
@@ -2,25 +2,33 @@ import { dfdlT } from "@monstermann/dfdl";
|
|
|
2
2
|
|
|
3
3
|
//#region src/Set/isSupersetOf.ts
|
|
4
4
|
/**
|
|
5
|
+
* # isSupersetOf
|
|
6
|
+
*
|
|
5
7
|
* ```ts
|
|
6
|
-
* function Set.isSupersetOf(
|
|
8
|
+
* function Set.isSupersetOf<T>(
|
|
9
|
+
* target: ReadonlySet<T>,
|
|
10
|
+
* source: ReadonlySet<NoInfer<T>>,
|
|
11
|
+
* ): boolean
|
|
7
12
|
* ```
|
|
8
13
|
*
|
|
9
|
-
*
|
|
14
|
+
* Returns `true` if the target set contains all values from the source set, `false` otherwise.
|
|
10
15
|
*
|
|
11
|
-
*
|
|
16
|
+
* ## Example
|
|
17
|
+
*
|
|
18
|
+
* ```ts [data-first]
|
|
12
19
|
* import { Set } from "@monstermann/set";
|
|
13
20
|
*
|
|
14
21
|
* Set.isSupersetOf(Set.create([1, 2, 3]), Set.create([1, 2])); // true
|
|
15
22
|
* Set.isSupersetOf(Set.create([1, 2, 3]), Set.create([1, 4])); // false
|
|
16
23
|
* ```
|
|
17
24
|
*
|
|
18
|
-
* ```ts
|
|
25
|
+
* ```ts [data-last]
|
|
19
26
|
* import { Set } from "@monstermann/set";
|
|
20
27
|
*
|
|
21
28
|
* pipe(Set.create([1, 2, 3]), Set.isSupersetOf(Set.create([1, 2]))); // true
|
|
22
29
|
* pipe(Set.create([1, 2, 3]), Set.isSupersetOf(Set.create([1, 4]))); // false
|
|
23
30
|
* ```
|
|
31
|
+
*
|
|
24
32
|
*/
|
|
25
33
|
const isSupersetOf = dfdlT((target, source) => {
|
|
26
34
|
if (target.size < source.size) return false;
|
package/dist/Set/mapEach.d.mts
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
//#region src/Set/mapEach.d.ts
|
|
2
2
|
/**
|
|
3
|
+
* # mapEach
|
|
4
|
+
*
|
|
3
5
|
* ```ts
|
|
4
|
-
* function Set.mapEach
|
|
6
|
+
* function Set.mapEach<T, U>(
|
|
7
|
+
* target: ReadonlySet<T>,
|
|
8
|
+
* fn: (
|
|
9
|
+
* value: NoInfer<T>,
|
|
10
|
+
* target: ReadonlySet<NoInfer<T>>,
|
|
11
|
+
* ) => U,
|
|
12
|
+
* ): ReadonlySet<U>
|
|
5
13
|
* ```
|
|
6
14
|
*
|
|
7
|
-
*
|
|
15
|
+
* Returns a new set with each value transformed by the mapping function.
|
|
8
16
|
*
|
|
9
|
-
*
|
|
17
|
+
* ## Example
|
|
18
|
+
*
|
|
19
|
+
* ```ts [data-first]
|
|
10
20
|
* import { Set } from "@monstermann/set";
|
|
11
21
|
*
|
|
12
22
|
* Set.mapEach(Set.create([1, 2, 3]), (x) => x * 2); // Set([2, 4, 6])
|
|
13
23
|
* Set.mapEach(Set.create(["a", "b"]), (x) => x.toUpperCase()); // Set(['A', 'B'])
|
|
14
24
|
* ```
|
|
15
25
|
*
|
|
16
|
-
* ```ts
|
|
26
|
+
* ```ts [data-last]
|
|
17
27
|
* import { Set } from "@monstermann/set";
|
|
18
28
|
*
|
|
19
29
|
* pipe(
|
|
@@ -26,6 +36,7 @@
|
|
|
26
36
|
* Set.mapEach((x) => x.toUpperCase()),
|
|
27
37
|
* ); // Set(['A', 'B'])
|
|
28
38
|
* ```
|
|
39
|
+
*
|
|
29
40
|
*/
|
|
30
41
|
declare const mapEach: {
|
|
31
42
|
<T, U>(fn: (value: NoInfer<T>, target: ReadonlySet<NoInfer<T>>) => U): (target: Set<T>) => Set<U>;
|
package/dist/Set/mapEach.mjs
CHANGED
|
@@ -2,20 +2,30 @@ import { dfdlT } from "@monstermann/dfdl";
|
|
|
2
2
|
|
|
3
3
|
//#region src/Set/mapEach.ts
|
|
4
4
|
/**
|
|
5
|
+
* # mapEach
|
|
6
|
+
*
|
|
5
7
|
* ```ts
|
|
6
|
-
* function Set.mapEach
|
|
8
|
+
* function Set.mapEach<T, U>(
|
|
9
|
+
* target: ReadonlySet<T>,
|
|
10
|
+
* fn: (
|
|
11
|
+
* value: NoInfer<T>,
|
|
12
|
+
* target: ReadonlySet<NoInfer<T>>,
|
|
13
|
+
* ) => U,
|
|
14
|
+
* ): ReadonlySet<U>
|
|
7
15
|
* ```
|
|
8
16
|
*
|
|
9
|
-
*
|
|
17
|
+
* Returns a new set with each value transformed by the mapping function.
|
|
10
18
|
*
|
|
11
|
-
*
|
|
19
|
+
* ## Example
|
|
20
|
+
*
|
|
21
|
+
* ```ts [data-first]
|
|
12
22
|
* import { Set } from "@monstermann/set";
|
|
13
23
|
*
|
|
14
24
|
* Set.mapEach(Set.create([1, 2, 3]), (x) => x * 2); // Set([2, 4, 6])
|
|
15
25
|
* Set.mapEach(Set.create(["a", "b"]), (x) => x.toUpperCase()); // Set(['A', 'B'])
|
|
16
26
|
* ```
|
|
17
27
|
*
|
|
18
|
-
* ```ts
|
|
28
|
+
* ```ts [data-last]
|
|
19
29
|
* import { Set } from "@monstermann/set";
|
|
20
30
|
*
|
|
21
31
|
* pipe(
|
|
@@ -28,6 +38,7 @@ import { dfdlT } from "@monstermann/dfdl";
|
|
|
28
38
|
* Set.mapEach((x) => x.toUpperCase()),
|
|
29
39
|
* ); // Set(['A', 'B'])
|
|
30
40
|
* ```
|
|
41
|
+
*
|
|
31
42
|
*/
|
|
32
43
|
const mapEach = dfdlT((target, fn) => {
|
|
33
44
|
let hasChanges = false;
|
package/dist/Set/remove.d.mts
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
//#region src/Set/remove.d.ts
|
|
2
2
|
/**
|
|
3
|
+
* # remove
|
|
4
|
+
*
|
|
3
5
|
* ```ts
|
|
4
|
-
* function Set.remove(
|
|
6
|
+
* function Set.remove<T>(
|
|
7
|
+
* target: ReadonlySet<T>,
|
|
8
|
+
* value: NoInfer<T>,
|
|
9
|
+
* ): ReadonlySet<T>
|
|
5
10
|
* ```
|
|
6
11
|
*
|
|
7
|
-
*
|
|
12
|
+
* Returns a set with the value removed. If the value doesn't exist in the set, returns the original set unchanged.
|
|
8
13
|
*
|
|
9
|
-
*
|
|
14
|
+
* ## Example
|
|
15
|
+
*
|
|
16
|
+
* ```ts [data-first]
|
|
10
17
|
* import { Set } from "@monstermann/set";
|
|
11
18
|
*
|
|
12
19
|
* Set.remove(Set.create([1, 2, 3]), 2); // Set([1, 3])
|
|
13
20
|
* Set.remove(Set.create([1, 2, 3]), 4); // Set([1, 2, 3])
|
|
14
21
|
* ```
|
|
15
22
|
*
|
|
16
|
-
* ```ts
|
|
23
|
+
* ```ts [data-last]
|
|
17
24
|
* import { Set } from "@monstermann/set";
|
|
18
25
|
*
|
|
19
26
|
* pipe(Set.create([1, 2, 3]), Set.remove(2)); // Set([1, 3])
|
|
20
27
|
* pipe(Set.create([1, 2, 3]), Set.remove(4)); // Set([1, 2, 3])
|
|
21
28
|
* ```
|
|
29
|
+
*
|
|
22
30
|
*/
|
|
23
31
|
declare const remove: {
|
|
24
32
|
<T>(value: NoInfer<T>): (target: Set<T>) => Set<T>;
|
package/dist/Set/remove.mjs
CHANGED
|
@@ -3,25 +3,33 @@ import { cloneSet } from "@monstermann/remmi";
|
|
|
3
3
|
|
|
4
4
|
//#region src/Set/remove.ts
|
|
5
5
|
/**
|
|
6
|
+
* # remove
|
|
7
|
+
*
|
|
6
8
|
* ```ts
|
|
7
|
-
* function Set.remove(
|
|
9
|
+
* function Set.remove<T>(
|
|
10
|
+
* target: ReadonlySet<T>,
|
|
11
|
+
* value: NoInfer<T>,
|
|
12
|
+
* ): ReadonlySet<T>
|
|
8
13
|
* ```
|
|
9
14
|
*
|
|
10
|
-
*
|
|
15
|
+
* Returns a set with the value removed. If the value doesn't exist in the set, returns the original set unchanged.
|
|
11
16
|
*
|
|
12
|
-
*
|
|
17
|
+
* ## Example
|
|
18
|
+
*
|
|
19
|
+
* ```ts [data-first]
|
|
13
20
|
* import { Set } from "@monstermann/set";
|
|
14
21
|
*
|
|
15
22
|
* Set.remove(Set.create([1, 2, 3]), 2); // Set([1, 3])
|
|
16
23
|
* Set.remove(Set.create([1, 2, 3]), 4); // Set([1, 2, 3])
|
|
17
24
|
* ```
|
|
18
25
|
*
|
|
19
|
-
* ```ts
|
|
26
|
+
* ```ts [data-last]
|
|
20
27
|
* import { Set } from "@monstermann/set";
|
|
21
28
|
*
|
|
22
29
|
* pipe(Set.create([1, 2, 3]), Set.remove(2)); // Set([1, 3])
|
|
23
30
|
* pipe(Set.create([1, 2, 3]), Set.remove(4)); // Set([1, 2, 3])
|
|
24
31
|
* ```
|
|
32
|
+
*
|
|
25
33
|
*/
|
|
26
34
|
const remove = dfdlT((target, value) => {
|
|
27
35
|
if (!target.has(value)) return target;
|
package/dist/Set/removeAll.d.mts
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
//#region src/Set/removeAll.d.ts
|
|
2
2
|
/**
|
|
3
|
+
* # removeAll
|
|
4
|
+
*
|
|
3
5
|
* ```ts
|
|
4
|
-
* function Set.removeAll(
|
|
6
|
+
* function Set.removeAll<T>(
|
|
7
|
+
* target: ReadonlySet<T>,
|
|
8
|
+
* values: Iterable<NoInfer<T>>,
|
|
9
|
+
* ): ReadonlySet<T>
|
|
5
10
|
* ```
|
|
6
11
|
*
|
|
7
|
-
*
|
|
12
|
+
* Returns a set with all values from the iterable removed. Values that don't exist in the set are skipped.
|
|
8
13
|
*
|
|
9
|
-
*
|
|
14
|
+
* ## Example
|
|
15
|
+
*
|
|
16
|
+
* ```ts [data-first]
|
|
10
17
|
* import { Set } from "@monstermann/set";
|
|
11
18
|
*
|
|
12
19
|
* Set.removeAll(Set.create([1, 2, 3, 4]), [2, 3]); // Set([1, 4])
|
|
13
20
|
* Set.removeAll(Set.create([1, 2, 3]), [4, 5]); // Set([1, 2, 3])
|
|
14
21
|
* ```
|
|
15
22
|
*
|
|
16
|
-
* ```ts
|
|
23
|
+
* ```ts [data-last]
|
|
17
24
|
* import { Set } from "@monstermann/set";
|
|
18
25
|
*
|
|
19
26
|
* pipe(Set.create([1, 2, 3, 4]), Set.removeAll([2, 3])); // Set([1, 4])
|
|
20
27
|
* pipe(Set.create([1, 2, 3]), Set.removeAll([4, 5])); // Set([1, 2, 3])
|
|
21
28
|
* ```
|
|
29
|
+
*
|
|
22
30
|
*/
|
|
23
31
|
declare const removeAll: {
|
|
24
32
|
<T>(values: Iterable<NoInfer<T>>): (target: Set<T>) => Set<T>;
|
package/dist/Set/removeAll.mjs
CHANGED
|
@@ -3,25 +3,33 @@ import { cloneSet } from "@monstermann/remmi";
|
|
|
3
3
|
|
|
4
4
|
//#region src/Set/removeAll.ts
|
|
5
5
|
/**
|
|
6
|
+
* # removeAll
|
|
7
|
+
*
|
|
6
8
|
* ```ts
|
|
7
|
-
* function Set.removeAll(
|
|
9
|
+
* function Set.removeAll<T>(
|
|
10
|
+
* target: ReadonlySet<T>,
|
|
11
|
+
* values: Iterable<NoInfer<T>>,
|
|
12
|
+
* ): ReadonlySet<T>
|
|
8
13
|
* ```
|
|
9
14
|
*
|
|
10
|
-
*
|
|
15
|
+
* Returns a set with all values from the iterable removed. Values that don't exist in the set are skipped.
|
|
11
16
|
*
|
|
12
|
-
*
|
|
17
|
+
* ## Example
|
|
18
|
+
*
|
|
19
|
+
* ```ts [data-first]
|
|
13
20
|
* import { Set } from "@monstermann/set";
|
|
14
21
|
*
|
|
15
22
|
* Set.removeAll(Set.create([1, 2, 3, 4]), [2, 3]); // Set([1, 4])
|
|
16
23
|
* Set.removeAll(Set.create([1, 2, 3]), [4, 5]); // Set([1, 2, 3])
|
|
17
24
|
* ```
|
|
18
25
|
*
|
|
19
|
-
* ```ts
|
|
26
|
+
* ```ts [data-last]
|
|
20
27
|
* import { Set } from "@monstermann/set";
|
|
21
28
|
*
|
|
22
29
|
* pipe(Set.create([1, 2, 3, 4]), Set.removeAll([2, 3])); // Set([1, 4])
|
|
23
30
|
* pipe(Set.create([1, 2, 3]), Set.removeAll([4, 5])); // Set([1, 2, 3])
|
|
24
31
|
* ```
|
|
32
|
+
*
|
|
25
33
|
*/
|
|
26
34
|
const removeAll = dfdlT((target, values) => {
|
|
27
35
|
let result;
|
package/dist/Set/size.d.mts
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
//#region src/Set/size.d.ts
|
|
2
2
|
/**
|
|
3
|
+
* # size
|
|
4
|
+
*
|
|
3
5
|
* ```ts
|
|
4
|
-
* function Set.size(
|
|
6
|
+
* function Set.size<T extends ReadonlySet<unknown>>(
|
|
7
|
+
* target: T,
|
|
8
|
+
* ): number
|
|
5
9
|
* ```
|
|
6
10
|
*
|
|
7
|
-
*
|
|
11
|
+
* Returns the number of values in the set.
|
|
8
12
|
*
|
|
9
|
-
*
|
|
13
|
+
* ## Example
|
|
14
|
+
*
|
|
15
|
+
* ```ts [data-first]
|
|
10
16
|
* import { Set } from "@monstermann/set";
|
|
11
17
|
*
|
|
12
18
|
* Set.size(Set.create([1, 2, 3])); // 3
|
|
13
19
|
* Set.size(Set.create()); // 0
|
|
14
20
|
* ```
|
|
15
21
|
*
|
|
16
|
-
* ```ts
|
|
22
|
+
* ```ts [data-last]
|
|
17
23
|
* import { Set } from "@monstermann/set";
|
|
18
24
|
*
|
|
19
25
|
* pipe(Set.create([1, 2, 3]), Set.size()); // 3
|
|
20
26
|
* pipe(Set.create(), Set.size()); // 0
|
|
21
27
|
* ```
|
|
28
|
+
*
|
|
22
29
|
*/
|
|
23
30
|
declare const size: {
|
|
24
31
|
(): <T extends ReadonlySet<unknown>>(target: T) => number;
|
package/dist/Set/size.mjs
CHANGED
|
@@ -2,25 +2,32 @@ import { dfdlT } from "@monstermann/dfdl";
|
|
|
2
2
|
|
|
3
3
|
//#region src/Set/size.ts
|
|
4
4
|
/**
|
|
5
|
+
* # size
|
|
6
|
+
*
|
|
5
7
|
* ```ts
|
|
6
|
-
* function Set.size(
|
|
8
|
+
* function Set.size<T extends ReadonlySet<unknown>>(
|
|
9
|
+
* target: T,
|
|
10
|
+
* ): number
|
|
7
11
|
* ```
|
|
8
12
|
*
|
|
9
|
-
*
|
|
13
|
+
* Returns the number of values in the set.
|
|
10
14
|
*
|
|
11
|
-
*
|
|
15
|
+
* ## Example
|
|
16
|
+
*
|
|
17
|
+
* ```ts [data-first]
|
|
12
18
|
* import { Set } from "@monstermann/set";
|
|
13
19
|
*
|
|
14
20
|
* Set.size(Set.create([1, 2, 3])); // 3
|
|
15
21
|
* Set.size(Set.create()); // 0
|
|
16
22
|
* ```
|
|
17
23
|
*
|
|
18
|
-
* ```ts
|
|
24
|
+
* ```ts [data-last]
|
|
19
25
|
* import { Set } from "@monstermann/set";
|
|
20
26
|
*
|
|
21
27
|
* pipe(Set.create([1, 2, 3]), Set.size()); // 3
|
|
22
28
|
* pipe(Set.create(), Set.size()); // 0
|
|
23
29
|
* ```
|
|
30
|
+
*
|
|
24
31
|
*/
|
|
25
32
|
const size = dfdlT((target) => {
|
|
26
33
|
return target.size;
|
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
//#region src/Set/symmetricDifference.d.ts
|
|
2
2
|
/**
|
|
3
|
+
* # symmetricDifference
|
|
4
|
+
*
|
|
3
5
|
* ```ts
|
|
4
|
-
* function Set.symmetricDifference
|
|
6
|
+
* function Set.symmetricDifference<T, U>(
|
|
7
|
+
* target: Set<T>,
|
|
8
|
+
* source: Set<U>,
|
|
9
|
+
* ): Set<T | U>
|
|
5
10
|
* ```
|
|
6
11
|
*
|
|
7
|
-
*
|
|
12
|
+
* Returns a set containing values that exist in either set but not in both.
|
|
8
13
|
*
|
|
9
|
-
*
|
|
14
|
+
* ## Example
|
|
15
|
+
*
|
|
16
|
+
* ```ts [data-first]
|
|
10
17
|
* import { Set } from "@monstermann/set";
|
|
11
18
|
*
|
|
12
19
|
* Set.symmetricDifference(Set.create([1, 2, 3]), Set.create([3, 4, 5])); // Set([1, 2, 4, 5])
|
|
13
20
|
* Set.symmetricDifference(Set.create([1, 2]), Set.create([3, 4])); // Set([1, 2, 3, 4])
|
|
14
21
|
* ```
|
|
15
22
|
*
|
|
16
|
-
* ```ts
|
|
23
|
+
* ```ts [data-last]
|
|
17
24
|
* import { Set } from "@monstermann/set";
|
|
18
25
|
*
|
|
19
26
|
* pipe(Set.create([1, 2, 3]), Set.symmetricDifference(Set.create([3, 4, 5]))); // Set([1, 2, 4, 5])
|
|
20
27
|
* pipe(Set.create([1, 2]), Set.symmetricDifference(Set.create([3, 4]))); // Set([1, 2, 3, 4])
|
|
21
28
|
* ```
|
|
29
|
+
*
|
|
22
30
|
*/
|
|
23
31
|
declare const symmetricDifference: {
|
|
24
32
|
<T, U>(source: Set<U>): (target: Set<T>) => Set<T | U>;
|
|
@@ -2,44 +2,50 @@ import { dfdlT } from "@monstermann/dfdl";
|
|
|
2
2
|
|
|
3
3
|
//#region src/Set/symmetricDifference.ts
|
|
4
4
|
/**
|
|
5
|
+
* # symmetricDifference
|
|
6
|
+
*
|
|
5
7
|
* ```ts
|
|
6
|
-
* function Set.symmetricDifference
|
|
8
|
+
* function Set.symmetricDifference<T, U>(
|
|
9
|
+
* target: Set<T>,
|
|
10
|
+
* source: Set<U>,
|
|
11
|
+
* ): Set<T | U>
|
|
7
12
|
* ```
|
|
8
13
|
*
|
|
9
|
-
*
|
|
14
|
+
* Returns a set containing values that exist in either set but not in both.
|
|
10
15
|
*
|
|
11
|
-
*
|
|
16
|
+
* ## Example
|
|
17
|
+
*
|
|
18
|
+
* ```ts [data-first]
|
|
12
19
|
* import { Set } from "@monstermann/set";
|
|
13
20
|
*
|
|
14
21
|
* Set.symmetricDifference(Set.create([1, 2, 3]), Set.create([3, 4, 5])); // Set([1, 2, 4, 5])
|
|
15
22
|
* Set.symmetricDifference(Set.create([1, 2]), Set.create([3, 4])); // Set([1, 2, 3, 4])
|
|
16
23
|
* ```
|
|
17
24
|
*
|
|
18
|
-
* ```ts
|
|
25
|
+
* ```ts [data-last]
|
|
19
26
|
* import { Set } from "@monstermann/set";
|
|
20
27
|
*
|
|
21
28
|
* pipe(Set.create([1, 2, 3]), Set.symmetricDifference(Set.create([3, 4, 5]))); // Set([1, 2, 4, 5])
|
|
22
29
|
* pipe(Set.create([1, 2]), Set.symmetricDifference(Set.create([3, 4]))); // Set([1, 2, 3, 4])
|
|
23
30
|
* ```
|
|
31
|
+
*
|
|
24
32
|
*/
|
|
25
33
|
const symmetricDifference = dfdlT((target, source) => {
|
|
26
34
|
if (source.size === 0) return target;
|
|
27
35
|
if (target.size === 0) return source;
|
|
28
|
-
let
|
|
36
|
+
let result;
|
|
37
|
+
let allMatch = true;
|
|
29
38
|
for (const a of target) if (!source.has(a)) {
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
allMatch = false;
|
|
40
|
+
result ??= /* @__PURE__ */ new Set();
|
|
41
|
+
result.add(a);
|
|
32
42
|
}
|
|
33
|
-
if (!
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
43
|
+
for (const b of source) if (!target.has(b)) {
|
|
44
|
+
allMatch = false;
|
|
45
|
+
result ??= /* @__PURE__ */ new Set();
|
|
46
|
+
result.add(b);
|
|
38
47
|
}
|
|
39
|
-
if (
|
|
40
|
-
const result = /* @__PURE__ */ new Set();
|
|
41
|
-
for (const a of target) if (!source.has(a)) result.add(a);
|
|
42
|
-
for (const b of source) if (!target.has(b)) result.add(b);
|
|
48
|
+
if (allMatch) return /* @__PURE__ */ new Set();
|
|
43
49
|
return result;
|
|
44
50
|
}, 2);
|
|
45
51
|
|
package/dist/Set/toArray.d.mts
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
//#region src/Set/toArray.d.ts
|
|
2
2
|
/**
|
|
3
|
+
* # toArray
|
|
4
|
+
*
|
|
3
5
|
* ```ts
|
|
4
|
-
* function Set.toArray(target)
|
|
6
|
+
* function Set.toArray<T>(target: ReadonlySet<T>): T[]
|
|
5
7
|
* ```
|
|
6
8
|
*
|
|
7
|
-
*
|
|
9
|
+
* Converts the set to an array.
|
|
8
10
|
*
|
|
9
|
-
*
|
|
11
|
+
* ## Example
|
|
12
|
+
*
|
|
13
|
+
* ```ts [data-first]
|
|
10
14
|
* import { Set } from "@monstermann/set";
|
|
11
15
|
*
|
|
12
16
|
* Set.toArray(Set.create([1, 2, 3])); // [1, 2, 3]
|
|
13
17
|
* Set.toArray(Set.create(["a", "b"])); // ['a', 'b']
|
|
14
18
|
* ```
|
|
15
19
|
*
|
|
16
|
-
* ```ts
|
|
20
|
+
* ```ts [data-last]
|
|
17
21
|
* import { Set } from "@monstermann/set";
|
|
18
22
|
*
|
|
19
23
|
* pipe(Set.create([1, 2, 3]), Set.toArray()); // [1, 2, 3]
|
|
20
24
|
* pipe(Set.create(["a", "b"]), Set.toArray()); // ['a', 'b']
|
|
21
25
|
* ```
|
|
26
|
+
*
|
|
22
27
|
*/
|
|
23
28
|
declare const toArray: {
|
|
24
29
|
(): <T>(target: ReadonlySet<T>) => T[];
|
package/dist/Set/toArray.mjs
CHANGED
|
@@ -2,25 +2,30 @@ import { dfdlT } from "@monstermann/dfdl";
|
|
|
2
2
|
|
|
3
3
|
//#region src/Set/toArray.ts
|
|
4
4
|
/**
|
|
5
|
+
* # toArray
|
|
6
|
+
*
|
|
5
7
|
* ```ts
|
|
6
|
-
* function Set.toArray(target)
|
|
8
|
+
* function Set.toArray<T>(target: ReadonlySet<T>): T[]
|
|
7
9
|
* ```
|
|
8
10
|
*
|
|
9
|
-
*
|
|
11
|
+
* Converts the set to an array.
|
|
10
12
|
*
|
|
11
|
-
*
|
|
13
|
+
* ## Example
|
|
14
|
+
*
|
|
15
|
+
* ```ts [data-first]
|
|
12
16
|
* import { Set } from "@monstermann/set";
|
|
13
17
|
*
|
|
14
18
|
* Set.toArray(Set.create([1, 2, 3])); // [1, 2, 3]
|
|
15
19
|
* Set.toArray(Set.create(["a", "b"])); // ['a', 'b']
|
|
16
20
|
* ```
|
|
17
21
|
*
|
|
18
|
-
* ```ts
|
|
22
|
+
* ```ts [data-last]
|
|
19
23
|
* import { Set } from "@monstermann/set";
|
|
20
24
|
*
|
|
21
25
|
* pipe(Set.create([1, 2, 3]), Set.toArray()); // [1, 2, 3]
|
|
22
26
|
* pipe(Set.create(["a", "b"]), Set.toArray()); // ['a', 'b']
|
|
23
27
|
* ```
|
|
28
|
+
*
|
|
24
29
|
*/
|
|
25
30
|
const toArray = dfdlT((target) => {
|
|
26
31
|
return Array.from(target);
|
package/dist/Set/union.d.mts
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
//#region src/Set/union.d.ts
|
|
2
2
|
/**
|
|
3
|
+
* # union
|
|
4
|
+
*
|
|
3
5
|
* ```ts
|
|
4
|
-
* function Set.union
|
|
6
|
+
* function Set.union<T, U>(
|
|
7
|
+
* target: Set<T>,
|
|
8
|
+
* source: Set<U>,
|
|
9
|
+
* ): Set<T | U>
|
|
5
10
|
* ```
|
|
6
11
|
*
|
|
7
|
-
*
|
|
12
|
+
* Returns a set containing all values from both sets.
|
|
8
13
|
*
|
|
9
|
-
*
|
|
14
|
+
* ## Example
|
|
15
|
+
*
|
|
16
|
+
* ```ts [data-first]
|
|
10
17
|
* import { Set } from "@monstermann/set";
|
|
11
18
|
*
|
|
12
19
|
* Set.union(Set.create([1, 2]), Set.create([2, 3, 4])); // Set([1, 2, 3, 4])
|
|
13
20
|
* Set.union(Set.create([1, 2]), Set.create([3, 4])); // Set([1, 2, 3, 4])
|
|
14
21
|
* ```
|
|
15
22
|
*
|
|
16
|
-
* ```ts
|
|
23
|
+
* ```ts [data-last]
|
|
17
24
|
* import { Set } from "@monstermann/set";
|
|
18
25
|
*
|
|
19
26
|
* pipe(Set.create([1, 2]), Set.union(Set.create([2, 3, 4]))); // Set([1, 2, 3, 4])
|
|
20
27
|
* pipe(Set.create([1, 2]), Set.union(Set.create([3, 4]))); // Set([1, 2, 3, 4])
|
|
21
28
|
* ```
|
|
29
|
+
*
|
|
22
30
|
*/
|
|
23
31
|
declare const union: {
|
|
24
32
|
<T, U>(source: Set<U>): (target: Set<T>) => Set<T | U>;
|