@nunofyobiz/effect-extras 1.0.0 → 2.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nunofyobiz/effect-extras",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "Generic, framework-agnostic extensions of the Effect standard library (ArrayX, OptionX, RecordX, StructX, …).",
5
5
  "keywords": [
6
6
  "effect",
@@ -14,7 +14,7 @@ import {
14
14
  } from "effect";
15
15
  import { dual, identity } from "effect/Function";
16
16
  import { RecordX } from "../RecordX";
17
- import { These } from "../These";
17
+ import { WarnResult } from "../WarnResult";
18
18
  import { ResultX } from "../ResultX";
19
19
 
20
20
  /**
@@ -48,50 +48,52 @@ export const slice = dual<
48
48
  );
49
49
 
50
50
  /**
51
- * Zips two arrays into one, calling `f` with a `These` for each index so that
52
- * length mismatches are handled explicitly rather than truncated.
51
+ * Zips two arrays into one, calling `f` with a `WarnResult` for each index so
52
+ * that length mismatches are handled explicitly rather than truncated.
53
53
  *
54
54
  * Unlike `Array.zipWith` (which stops at the shorter array), this walks to the
55
- * length of the *longer* array. At each index `f` receives a `These.These<A, B>`:
56
- * `LeftAndRight` when both arrays have an element, `LeftOnly` when only the
57
- * first does, and `RightOnly` when only the second does. Use it when the
58
- * "extra" tail of either array still carries meaning.
55
+ * length of the *longer* array. The first array's element fills the `warnings`
56
+ * side and the second array's element fills the `success` side, so at each index
57
+ * `f` receives a `WarnResult.WarnResult<A, B>`: `SuccessWithWarnings` when both
58
+ * arrays have an element, `WarningsOnly` when only the first does, and
59
+ * `SuccessOnly` when only the second does. Use it when the "extra" tail of either
60
+ * array still carries meaning.
59
61
  *
60
62
  * @example
61
63
  * ```ts
62
- * import { ArrayX, These } from "@nunofyobiz/effect-extras"
64
+ * import { ArrayX, WarnResult } from "@nunofyobiz/effect-extras"
63
65
  *
64
- * const describe = These.match({
65
- * LeftOnly: ({ left }) => `left ${left}`,
66
- * RightOnly: ({ right }) => `right ${right}`,
67
- * LeftAndRight: ({ left, right }) => `both ${left}/${right}`,
66
+ * const describe = WarnResult.match({
67
+ * WarningsOnly: ({ warnings }) => `warnings ${warnings}`,
68
+ * SuccessOnly: ({ success }) => `success ${success}`,
69
+ * SuccessWithWarnings: ({ warnings, success }) => `both ${warnings}/${success}`,
68
70
  * })
69
71
  *
70
- * assert.deepStrictEqual(ArrayX.zipWithThese([1, 2, 3], [10, 20], describe), [
72
+ * assert.deepStrictEqual(ArrayX.zipWithWarnings([1, 2, 3], [10, 20], describe), [
71
73
  * "both 1/10",
72
74
  * "both 2/20",
73
- * "left 3",
75
+ * "warnings 3",
74
76
  * ])
75
77
  * ```
76
78
  *
77
79
  * @category combinators
78
80
  * @since 0.0.0
79
81
  */
80
- export const zipWithThese = dual<
82
+ export const zipWithWarnings = dual<
81
83
  <A, B, C>(
82
- f: (ab: These.These<A, B>) => C,
84
+ f: (ab: WarnResult.WarnResult<A, B>) => C,
83
85
  ) => (array1: readonly A[], array2: readonly B[]) => C[],
84
86
  <A, B, C>(
85
87
  array1: readonly A[],
86
88
  array2: readonly B[],
87
- f: (ab: These.These<A, B>) => C,
89
+ f: (ab: WarnResult.WarnResult<A, B>) => C,
88
90
  ) => C[]
89
91
  >(
90
92
  3,
91
93
  <A, B, C>(
92
94
  array1: readonly A[],
93
95
  array2: readonly B[],
94
- f: (ab: These.These<A, B>) => C,
96
+ f: (ab: WarnResult.WarnResult<A, B>) => C,
95
97
  ): C[] => {
96
98
  const newLength = Math.max(array1.length, array2.length);
97
99
 
@@ -102,25 +104,25 @@ export const zipWithThese = dual<
102
104
  return Array.makeBy(newLength, (index) => {
103
105
  if (index < array1.length && index < array2.length) {
104
106
  return f(
105
- These.LeftAndRight({
106
- left: array1[index],
107
- right: array2[index],
107
+ WarnResult.SuccessWithWarnings({
108
+ warnings: array1[index],
109
+ success: array2[index],
108
110
  }),
109
111
  );
110
112
  }
111
113
 
112
114
  if (index < array1.length) {
113
115
  return f(
114
- These.LeftOnly({
115
- left: array1[index],
116
+ WarnResult.WarningsOnly({
117
+ warnings: array1[index],
116
118
  }),
117
119
  );
118
120
  }
119
121
 
120
122
  if (index < array2.length) {
121
123
  return f(
122
- These.RightOnly({
123
- right: array2[index],
124
+ WarnResult.SuccessOnly({
125
+ success: array2[index],
124
126
  }),
125
127
  );
126
128
  }