@monstermann/set 0.1.1 → 0.2.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.
@@ -24,15 +24,11 @@ import { dfdlT } from "@monstermann/dfdl";
24
24
  */
25
25
  const difference = dfdlT((target, source) => {
26
26
  if (source.size === 0) return target;
27
- for (const value of target) if (source.has(value)) {
28
- const result = /* @__PURE__ */ new Set();
29
- for (const value$1 of target) {
30
- if (source.has(value$1)) continue;
31
- result.add(value$1);
32
- }
33
- return result;
34
- }
35
- return target;
27
+ let hasOverlap = false;
28
+ const result = /* @__PURE__ */ new Set();
29
+ for (const value of target) if (source.has(value)) hasOverlap = true;
30
+ else result.add(value);
31
+ return hasOverlap ? result : target;
36
32
  }, 2);
37
33
 
38
34
  //#endregion
@@ -25,15 +25,11 @@ import { dfdlT } from "@monstermann/dfdl";
25
25
  const intersection = dfdlT((target, source) => {
26
26
  if (target.size === 0) return target;
27
27
  if (source.size === 0) return source;
28
- for (const value of target) if (!source.has(value)) {
29
- const result = /* @__PURE__ */ new Set();
30
- for (const value$1 of target) {
31
- if (!source.has(value$1)) continue;
32
- result.add(value$1);
33
- }
34
- return result;
35
- }
36
- return target;
28
+ let hasNonMatch = false;
29
+ const result = /* @__PURE__ */ new Set();
30
+ for (const value of target) if (!source.has(value)) hasNonMatch = true;
31
+ else result.add(value);
32
+ return hasNonMatch ? result : target;
37
33
  }, 2);
38
34
 
39
35
  //#endregion
@@ -25,21 +25,19 @@ import { dfdlT } from "@monstermann/dfdl";
25
25
  const symmetricDifference = dfdlT((target, source) => {
26
26
  if (source.size === 0) return target;
27
27
  if (target.size === 0) return source;
28
- let hasChanges = false;
28
+ let result;
29
+ let allMatch = true;
29
30
  for (const a of target) if (!source.has(a)) {
30
- hasChanges = true;
31
- break;
31
+ allMatch = false;
32
+ result ??= /* @__PURE__ */ new Set();
33
+ result.add(a);
32
34
  }
33
- if (!hasChanges) {
34
- for (const b of source) if (!target.has(b)) {
35
- hasChanges = true;
36
- break;
37
- }
35
+ for (const b of source) if (!target.has(b)) {
36
+ allMatch = false;
37
+ result ??= /* @__PURE__ */ new Set();
38
+ result.add(b);
38
39
  }
39
- if (!hasChanges) return /* @__PURE__ */ new Set();
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);
40
+ if (allMatch) return /* @__PURE__ */ new Set();
43
41
  return result;
44
42
  }, 2);
45
43
 
@@ -25,13 +25,15 @@ import { dfdlT } from "@monstermann/dfdl";
25
25
  const union = dfdlT((target, source) => {
26
26
  if (source.size === 0) return target;
27
27
  if (target.size === 0) return source;
28
+ let result;
28
29
  for (const element of source) if (!target.has(element)) {
29
- const result = /* @__PURE__ */ new Set();
30
- for (const a of target) result.add(a);
31
- for (const b of source) result.add(b);
32
- return result;
30
+ if (result === void 0) {
31
+ result = /* @__PURE__ */ new Set();
32
+ for (const a of target) result.add(a);
33
+ }
34
+ result.add(element);
33
35
  }
34
- return target;
36
+ return result ?? target;
35
37
  }, 2);
36
38
 
37
39
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@monstermann/set",
3
3
  "type": "module",
4
- "version": "0.1.1",
4
+ "version": "0.2.0",
5
5
  "description": "Functional utilities for sets.",
6
6
  "author": "Michael Ostermann <michaelostermann@me.com>",
7
7
  "license": "MIT",