@nunofyobiz/effect-extras 0.0.2 → 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/README.md +14 -4
- package/dist/index.d.ts +605 -536
- package/dist/index.js +148 -142
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/ArrayX/ArrayX.ts +27 -25
- package/src/WarnResult/WarnResult.ts +1265 -0
- package/src/WarnResult/index.ts +1 -0
- package/src/index.ts +1 -1
- package/src/These/These.ts +0 -1173
- package/src/These/index.ts +0 -1
package/package.json
CHANGED
package/src/ArrayX/ArrayX.ts
CHANGED
|
@@ -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 {
|
|
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 `
|
|
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.
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
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,
|
|
64
|
+
* import { ArrayX, WarnResult } from "@nunofyobiz/effect-extras"
|
|
63
65
|
*
|
|
64
|
-
* const describe =
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
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.
|
|
72
|
+
* assert.deepStrictEqual(ArrayX.zipWithWarnings([1, 2, 3], [10, 20], describe), [
|
|
71
73
|
* "both 1/10",
|
|
72
74
|
* "both 2/20",
|
|
73
|
-
* "
|
|
75
|
+
* "warnings 3",
|
|
74
76
|
* ])
|
|
75
77
|
* ```
|
|
76
78
|
*
|
|
77
79
|
* @category combinators
|
|
78
80
|
* @since 0.0.0
|
|
79
81
|
*/
|
|
80
|
-
export const
|
|
82
|
+
export const zipWithWarnings = dual<
|
|
81
83
|
<A, B, C>(
|
|
82
|
-
f: (ab:
|
|
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:
|
|
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:
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
115
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
+
WarnResult.SuccessOnly({
|
|
125
|
+
success: array2[index],
|
|
124
126
|
}),
|
|
125
127
|
);
|
|
126
128
|
}
|