@nlozgachev/pipelined 0.11.0 → 0.13.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 (193) hide show
  1. package/LICENCE +28 -0
  2. package/README.md +1 -1
  3. package/{types/src/Types/NonEmptyList.d.ts → dist/NonEmptyList-BlGFjor5.d.mts} +4 -3
  4. package/dist/NonEmptyList-BlGFjor5.d.ts +30 -0
  5. package/dist/Task-BB8Wmc1J.d.ts +677 -0
  6. package/dist/Task-ChKyH0pF.d.mts +677 -0
  7. package/dist/chunk-DBIC62UV.mjs +6 -0
  8. package/dist/chunk-QPTGO5AS.mjs +150 -0
  9. package/dist/composition.d.mts +495 -0
  10. package/dist/composition.d.ts +495 -0
  11. package/dist/composition.js +188 -0
  12. package/dist/composition.mjs +135 -0
  13. package/dist/core.d.mts +2170 -0
  14. package/dist/core.d.ts +2170 -0
  15. package/dist/core.js +698 -0
  16. package/dist/core.mjs +517 -0
  17. package/dist/types.d.mts +54 -0
  18. package/{types/src/Types/Brand.d.ts → dist/types.d.ts} +6 -4
  19. package/dist/types.js +41 -0
  20. package/dist/types.mjs +14 -0
  21. package/dist/utils.d.mts +1285 -0
  22. package/dist/utils.d.ts +1285 -0
  23. package/dist/utils.js +722 -0
  24. package/dist/utils.mjs +553 -0
  25. package/package.json +63 -69
  26. package/esm/mod.js +0 -3
  27. package/esm/package.json +0 -3
  28. package/esm/src/Composition/compose.js +0 -3
  29. package/esm/src/Composition/converge.js +0 -3
  30. package/esm/src/Composition/curry.js +0 -42
  31. package/esm/src/Composition/flip.js +0 -20
  32. package/esm/src/Composition/flow.js +0 -8
  33. package/esm/src/Composition/fn.js +0 -85
  34. package/esm/src/Composition/index.js +0 -13
  35. package/esm/src/Composition/juxt.js +0 -3
  36. package/esm/src/Composition/memoize.js +0 -66
  37. package/esm/src/Composition/not.js +0 -25
  38. package/esm/src/Composition/on.js +0 -12
  39. package/esm/src/Composition/pipe.js +0 -3
  40. package/esm/src/Composition/tap.js +0 -33
  41. package/esm/src/Composition/uncurry.js +0 -32
  42. package/esm/src/Core/Deferred.js +0 -30
  43. package/esm/src/Core/InternalTypes.js +0 -1
  44. package/esm/src/Core/Lens.js +0 -98
  45. package/esm/src/Core/Logged.js +0 -111
  46. package/esm/src/Core/Option.js +0 -191
  47. package/esm/src/Core/Optional.js +0 -160
  48. package/esm/src/Core/Predicate.js +0 -133
  49. package/esm/src/Core/Reader.js +0 -134
  50. package/esm/src/Core/Refinement.js +0 -115
  51. package/esm/src/Core/RemoteData.js +0 -211
  52. package/esm/src/Core/Result.js +0 -170
  53. package/esm/src/Core/State.js +0 -181
  54. package/esm/src/Core/Task.js +0 -223
  55. package/esm/src/Core/TaskOption.js +0 -106
  56. package/esm/src/Core/TaskResult.js +0 -127
  57. package/esm/src/Core/TaskValidation.js +0 -128
  58. package/esm/src/Core/These.js +0 -245
  59. package/esm/src/Core/Validation.js +0 -212
  60. package/esm/src/Core/index.js +0 -17
  61. package/esm/src/Types/Brand.js +0 -28
  62. package/esm/src/Types/NonEmptyList.js +0 -14
  63. package/esm/src/Types/index.js +0 -2
  64. package/esm/src/Utils/Arr.js +0 -570
  65. package/esm/src/Utils/Num.js +0 -124
  66. package/esm/src/Utils/Rec.js +0 -215
  67. package/esm/src/Utils/Str.js +0 -134
  68. package/esm/src/Utils/index.js +0 -4
  69. package/script/mod.js +0 -19
  70. package/script/package.json +0 -3
  71. package/script/src/Composition/compose.js +0 -6
  72. package/script/src/Composition/converge.js +0 -6
  73. package/script/src/Composition/curry.js +0 -48
  74. package/script/src/Composition/flip.js +0 -24
  75. package/script/src/Composition/flow.js +0 -11
  76. package/script/src/Composition/fn.js +0 -98
  77. package/script/src/Composition/index.js +0 -29
  78. package/script/src/Composition/juxt.js +0 -6
  79. package/script/src/Composition/memoize.js +0 -71
  80. package/script/src/Composition/not.js +0 -29
  81. package/script/src/Composition/on.js +0 -16
  82. package/script/src/Composition/pipe.js +0 -6
  83. package/script/src/Composition/tap.js +0 -37
  84. package/script/src/Composition/uncurry.js +0 -38
  85. package/script/src/Core/Deferred.js +0 -33
  86. package/script/src/Core/InternalTypes.js +0 -2
  87. package/script/src/Core/Lens.js +0 -101
  88. package/script/src/Core/Logged.js +0 -114
  89. package/script/src/Core/Option.js +0 -194
  90. package/script/src/Core/Optional.js +0 -163
  91. package/script/src/Core/Predicate.js +0 -136
  92. package/script/src/Core/Reader.js +0 -137
  93. package/script/src/Core/Refinement.js +0 -118
  94. package/script/src/Core/RemoteData.js +0 -214
  95. package/script/src/Core/Result.js +0 -173
  96. package/script/src/Core/State.js +0 -184
  97. package/script/src/Core/Task.js +0 -226
  98. package/script/src/Core/TaskOption.js +0 -109
  99. package/script/src/Core/TaskResult.js +0 -130
  100. package/script/src/Core/TaskValidation.js +0 -131
  101. package/script/src/Core/These.js +0 -248
  102. package/script/src/Core/Validation.js +0 -215
  103. package/script/src/Core/index.js +0 -33
  104. package/script/src/Types/Brand.js +0 -31
  105. package/script/src/Types/NonEmptyList.js +0 -18
  106. package/script/src/Types/index.js +0 -18
  107. package/script/src/Utils/Arr.js +0 -573
  108. package/script/src/Utils/Num.js +0 -127
  109. package/script/src/Utils/Rec.js +0 -218
  110. package/script/src/Utils/Str.js +0 -137
  111. package/script/src/Utils/index.js +0 -20
  112. package/types/mod.d.ts +0 -4
  113. package/types/mod.d.ts.map +0 -1
  114. package/types/src/Composition/compose.d.ts +0 -33
  115. package/types/src/Composition/compose.d.ts.map +0 -1
  116. package/types/src/Composition/converge.d.ts +0 -21
  117. package/types/src/Composition/converge.d.ts.map +0 -1
  118. package/types/src/Composition/curry.d.ts +0 -43
  119. package/types/src/Composition/curry.d.ts.map +0 -1
  120. package/types/src/Composition/flip.d.ts +0 -21
  121. package/types/src/Composition/flip.d.ts.map +0 -1
  122. package/types/src/Composition/flow.d.ts +0 -56
  123. package/types/src/Composition/flow.d.ts.map +0 -1
  124. package/types/src/Composition/fn.d.ts +0 -76
  125. package/types/src/Composition/fn.d.ts.map +0 -1
  126. package/types/src/Composition/index.d.ts +0 -14
  127. package/types/src/Composition/index.d.ts.map +0 -1
  128. package/types/src/Composition/juxt.d.ts +0 -18
  129. package/types/src/Composition/juxt.d.ts.map +0 -1
  130. package/types/src/Composition/memoize.d.ts +0 -46
  131. package/types/src/Composition/memoize.d.ts.map +0 -1
  132. package/types/src/Composition/not.d.ts +0 -26
  133. package/types/src/Composition/not.d.ts.map +0 -1
  134. package/types/src/Composition/on.d.ts +0 -13
  135. package/types/src/Composition/on.d.ts.map +0 -1
  136. package/types/src/Composition/pipe.d.ts +0 -56
  137. package/types/src/Composition/pipe.d.ts.map +0 -1
  138. package/types/src/Composition/tap.d.ts +0 -31
  139. package/types/src/Composition/tap.d.ts.map +0 -1
  140. package/types/src/Composition/uncurry.d.ts +0 -54
  141. package/types/src/Composition/uncurry.d.ts.map +0 -1
  142. package/types/src/Core/Deferred.d.ts +0 -49
  143. package/types/src/Core/Deferred.d.ts.map +0 -1
  144. package/types/src/Core/InternalTypes.d.ts +0 -23
  145. package/types/src/Core/InternalTypes.d.ts.map +0 -1
  146. package/types/src/Core/Lens.d.ts +0 -118
  147. package/types/src/Core/Lens.d.ts.map +0 -1
  148. package/types/src/Core/Logged.d.ts +0 -126
  149. package/types/src/Core/Logged.d.ts.map +0 -1
  150. package/types/src/Core/Option.d.ts +0 -209
  151. package/types/src/Core/Option.d.ts.map +0 -1
  152. package/types/src/Core/Optional.d.ts +0 -158
  153. package/types/src/Core/Optional.d.ts.map +0 -1
  154. package/types/src/Core/Predicate.d.ts +0 -161
  155. package/types/src/Core/Predicate.d.ts.map +0 -1
  156. package/types/src/Core/Reader.d.ts +0 -156
  157. package/types/src/Core/Reader.d.ts.map +0 -1
  158. package/types/src/Core/Refinement.d.ts +0 -138
  159. package/types/src/Core/Refinement.d.ts.map +0 -1
  160. package/types/src/Core/RemoteData.d.ts +0 -197
  161. package/types/src/Core/RemoteData.d.ts.map +0 -1
  162. package/types/src/Core/Result.d.ts +0 -182
  163. package/types/src/Core/Result.d.ts.map +0 -1
  164. package/types/src/Core/State.d.ts +0 -192
  165. package/types/src/Core/State.d.ts.map +0 -1
  166. package/types/src/Core/Task.d.ts +0 -219
  167. package/types/src/Core/Task.d.ts.map +0 -1
  168. package/types/src/Core/TaskOption.d.ts +0 -121
  169. package/types/src/Core/TaskOption.d.ts.map +0 -1
  170. package/types/src/Core/TaskResult.d.ts +0 -119
  171. package/types/src/Core/TaskResult.d.ts.map +0 -1
  172. package/types/src/Core/TaskValidation.d.ts +0 -144
  173. package/types/src/Core/TaskValidation.d.ts.map +0 -1
  174. package/types/src/Core/These.d.ts +0 -225
  175. package/types/src/Core/These.d.ts.map +0 -1
  176. package/types/src/Core/Validation.d.ts +0 -203
  177. package/types/src/Core/Validation.d.ts.map +0 -1
  178. package/types/src/Core/index.d.ts +0 -18
  179. package/types/src/Core/index.d.ts.map +0 -1
  180. package/types/src/Types/Brand.d.ts.map +0 -1
  181. package/types/src/Types/NonEmptyList.d.ts.map +0 -1
  182. package/types/src/Types/index.d.ts +0 -3
  183. package/types/src/Types/index.d.ts.map +0 -1
  184. package/types/src/Utils/Arr.d.ts +0 -403
  185. package/types/src/Utils/Arr.d.ts.map +0 -1
  186. package/types/src/Utils/Num.d.ts +0 -110
  187. package/types/src/Utils/Num.d.ts.map +0 -1
  188. package/types/src/Utils/Rec.d.ts +0 -143
  189. package/types/src/Utils/Rec.d.ts.map +0 -1
  190. package/types/src/Utils/Str.d.ts +0 -128
  191. package/types/src/Utils/Str.d.ts.map +0 -1
  192. package/types/src/Utils/index.d.ts +0 -5
  193. package/types/src/Utils/index.d.ts.map +0 -1
@@ -1,214 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RemoteData = void 0;
4
- const Option_js_1 = require("./Option.js");
5
- const Result_js_1 = require("./Result.js");
6
- const _notAsked = { kind: "NotAsked" };
7
- const _loading = { kind: "Loading" };
8
- var RemoteData;
9
- (function (RemoteData) {
10
- /**
11
- * Creates a NotAsked RemoteData.
12
- */
13
- RemoteData.notAsked = () => _notAsked;
14
- /**
15
- * Creates a Loading RemoteData.
16
- */
17
- RemoteData.loading = () => _loading;
18
- /**
19
- * Creates a Failure RemoteData with the given error.
20
- */
21
- RemoteData.failure = (error) => ({
22
- kind: "Failure",
23
- error,
24
- });
25
- /**
26
- * Creates a Success RemoteData with the given value.
27
- */
28
- RemoteData.success = (value) => ({
29
- kind: "Success",
30
- value,
31
- });
32
- /**
33
- * Type guard that checks if a RemoteData is NotAsked.
34
- */
35
- RemoteData.isNotAsked = (data) => data.kind === "NotAsked";
36
- /**
37
- * Type guard that checks if a RemoteData is Loading.
38
- */
39
- RemoteData.isLoading = (data) => data.kind === "Loading";
40
- /**
41
- * Type guard that checks if a RemoteData is Failure.
42
- */
43
- RemoteData.isFailure = (data) => data.kind === "Failure";
44
- /**
45
- * Type guard that checks if a RemoteData is Success.
46
- */
47
- RemoteData.isSuccess = (data) => data.kind === "Success";
48
- /**
49
- * Transforms the success value inside a RemoteData.
50
- *
51
- * @example
52
- * ```ts
53
- * pipe(RemoteData.success(5), RemoteData.map(n => n * 2)); // Success(10)
54
- * pipe(RemoteData.loading(), RemoteData.map(n => n * 2)); // Loading
55
- * ```
56
- */
57
- RemoteData.map = (f) => (data) => RemoteData.isSuccess(data) ? RemoteData.success(f(data.value)) : data;
58
- /**
59
- * Transforms the error value inside a RemoteData.
60
- *
61
- * @example
62
- * ```ts
63
- * pipe(RemoteData.failure("oops"), RemoteData.mapError(e => e.toUpperCase())); // Failure("OOPS")
64
- * ```
65
- */
66
- RemoteData.mapError = (f) => (data) => RemoteData.isFailure(data) ? RemoteData.failure(f(data.error)) : data;
67
- /**
68
- * Chains RemoteData computations. If the input is Success, passes the value to f.
69
- * Otherwise, propagates the current state.
70
- *
71
- * @example
72
- * ```ts
73
- * pipe(
74
- * RemoteData.success(5),
75
- * RemoteData.chain(n => n > 0 ? RemoteData.success(n) : RemoteData.failure("negative"))
76
- * );
77
- * ```
78
- */
79
- RemoteData.chain = (f) => (data) => RemoteData.isSuccess(data) ? f(data.value) : data;
80
- /**
81
- * Applies a function wrapped in a RemoteData to a value wrapped in a RemoteData.
82
- *
83
- * @example
84
- * ```ts
85
- * const add = (a: number) => (b: number) => a + b;
86
- * pipe(
87
- * RemoteData.success(add),
88
- * RemoteData.ap(RemoteData.success(5)),
89
- * RemoteData.ap(RemoteData.success(3))
90
- * ); // Success(8)
91
- * ```
92
- */
93
- RemoteData.ap = (arg) => (data) => {
94
- if (RemoteData.isSuccess(data) && RemoteData.isSuccess(arg)) {
95
- return RemoteData.success(data.value(arg.value));
96
- }
97
- if (RemoteData.isFailure(data))
98
- return data;
99
- if (RemoteData.isFailure(arg))
100
- return arg;
101
- if (RemoteData.isLoading(data) || RemoteData.isLoading(arg))
102
- return RemoteData.loading();
103
- return RemoteData.notAsked();
104
- };
105
- /**
106
- * Extracts the value from a RemoteData by providing handlers for all four cases.
107
- *
108
- * @example
109
- * ```ts
110
- * pipe(
111
- * userData,
112
- * RemoteData.fold(
113
- * () => "Not asked",
114
- * () => "Loading...",
115
- * e => `Error: ${e}`,
116
- * value => `Got: ${value}`
117
- * )
118
- * );
119
- * ```
120
- */
121
- RemoteData.fold = (onNotAsked, onLoading, onFailure, onSuccess) => (data) => {
122
- switch (data.kind) {
123
- case "NotAsked":
124
- return onNotAsked();
125
- case "Loading":
126
- return onLoading();
127
- case "Failure":
128
- return onFailure(data.error);
129
- case "Success":
130
- return onSuccess(data.value);
131
- }
132
- };
133
- /**
134
- * Pattern matches on a RemoteData, returning the result of the matching case.
135
- *
136
- * @example
137
- * ```ts
138
- * pipe(
139
- * userData,
140
- * RemoteData.match({
141
- * notAsked: () => "Click to load",
142
- * loading: () => "Loading...",
143
- * failure: e => `Error: ${e}`,
144
- * success: user => `Hello, ${user.name}!`
145
- * })
146
- * );
147
- * ```
148
- */
149
- RemoteData.match = (cases) => (data) => {
150
- switch (data.kind) {
151
- case "NotAsked":
152
- return cases.notAsked();
153
- case "Loading":
154
- return cases.loading();
155
- case "Failure":
156
- return cases.failure(data.error);
157
- case "Success":
158
- return cases.success(data.value);
159
- }
160
- };
161
- /**
162
- * Returns the success value or a default value if the RemoteData is not Success.
163
- * The default can be a different type, widening the result to `A | B`.
164
- *
165
- * @example
166
- * ```ts
167
- * pipe(RemoteData.success(5), RemoteData.getOrElse(() => 0)); // 5
168
- * pipe(RemoteData.loading(), RemoteData.getOrElse(() => 0)); // 0
169
- * pipe(RemoteData.loading<string, number>(), RemoteData.getOrElse(() => null)); // null — typed as number | null
170
- * ```
171
- */
172
- RemoteData.getOrElse = (defaultValue) => (data) => RemoteData.isSuccess(data) ? data.value : defaultValue();
173
- /**
174
- * Executes a side effect on the success value without changing the RemoteData.
175
- *
176
- * @example
177
- * ```ts
178
- * pipe(
179
- * RemoteData.success(5),
180
- * RemoteData.tap(n => console.log("Value:", n)),
181
- * RemoteData.map(n => n * 2)
182
- * );
183
- * ```
184
- */
185
- RemoteData.tap = (f) => (data) => {
186
- if (RemoteData.isSuccess(data))
187
- f(data.value);
188
- return data;
189
- };
190
- /**
191
- * Recovers from a Failure state by providing a fallback RemoteData.
192
- * The fallback can produce a different success type, widening the result to `RemoteData<E, A | B>`.
193
- */
194
- RemoteData.recover = (fallback) => (data) => RemoteData.isFailure(data) ? fallback(data.error) : data;
195
- /**
196
- * Converts a RemoteData to an Option.
197
- * Success becomes Some, all other states become None.
198
- */
199
- RemoteData.toOption = (data) => RemoteData.isSuccess(data) ? Option_js_1.Option.some(data.value) : Option_js_1.Option.none();
200
- /**
201
- * Converts a RemoteData to a Result.
202
- * Success becomes Ok, Failure becomes Err.
203
- * NotAsked and Loading become Err with the provided fallback error.
204
- *
205
- * @example
206
- * ```ts
207
- * pipe(
208
- * RemoteData.success(42),
209
- * RemoteData.toResult(() => "not loaded")
210
- * ); // Ok(42)
211
- * ```
212
- */
213
- RemoteData.toResult = (onNotReady) => (data) => RemoteData.isSuccess(data) ? Result_js_1.Result.ok(data.value) : Result_js_1.Result.err(RemoteData.isFailure(data) ? data.error : onNotReady());
214
- })(RemoteData || (exports.RemoteData = RemoteData = {}));
@@ -1,173 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Result = void 0;
4
- const Option_js_1 = require("./Option.js");
5
- var Result;
6
- (function (Result) {
7
- /**
8
- * Creates a successful Result with the given value.
9
- */
10
- Result.ok = (value) => ({ kind: "Ok", value });
11
- /**
12
- * Creates a failed Result with the given error.
13
- */
14
- Result.err = (error) => ({ kind: "Error", error });
15
- /**
16
- * Type guard that checks if an Result is Ok.
17
- */
18
- Result.isOk = (data) => data.kind === "Ok";
19
- /**
20
- * Type guard that checks if an Result is Err.
21
- */
22
- Result.isErr = (data) => data.kind === "Error";
23
- /**
24
- * Creates an Result from a function that may throw.
25
- * Catches any errors and transforms them using the onError function.
26
- *
27
- * @example
28
- * ```ts
29
- * const parseJson = (s: string): Result<string, unknown> =>
30
- * Result.tryCatch(
31
- * () => JSON.parse(s),
32
- * (e) => `Parse error: ${e}`
33
- * );
34
- * ```
35
- */
36
- Result.tryCatch = (f, onError) => {
37
- try {
38
- return Result.ok(f());
39
- }
40
- catch (e) {
41
- return Result.err(onError(e));
42
- }
43
- };
44
- /**
45
- * Transforms the success value inside an Result.
46
- *
47
- * @example
48
- * ```ts
49
- * pipe(Result.ok(5), Result.map(n => n * 2)); // Ok(10)
50
- * pipe(Result.err("error"), Result.map(n => n * 2)); // Err("error")
51
- * ```
52
- */
53
- Result.map = (f) => (data) => Result.isOk(data) ? Result.ok(f(data.value)) : data;
54
- /**
55
- * Transforms the error value inside an Result.
56
- *
57
- * @example
58
- * ```ts
59
- * pipe(Result.err("oops"), Result.mapError(e => e.toUpperCase())); // Err("OOPS")
60
- * ```
61
- */
62
- Result.mapError = (f) => (data) => Result.isErr(data) ? Result.err(f(data.error)) : data;
63
- /**
64
- * Chains Result computations. If the first is Ok, passes the value to f.
65
- * If the first is Err, propagates the error.
66
- *
67
- * @example
68
- * ```ts
69
- * const validatePositive = (n: number): Result<string, number> =>
70
- * n > 0 ? Result.ok(n) : Result.err("Must be positive");
71
- *
72
- * pipe(Result.ok(5), Result.chain(validatePositive)); // Ok(5)
73
- * pipe(Result.ok(-1), Result.chain(validatePositive)); // Err("Must be positive")
74
- * ```
75
- */
76
- Result.chain = (f) => (data) => Result.isOk(data) ? f(data.value) : data;
77
- /**
78
- * Extracts the value from an Result by providing handlers for both cases.
79
- *
80
- * @example
81
- * ```ts
82
- * pipe(
83
- * Result.ok(5),
84
- * Result.fold(
85
- * e => `Error: ${e}`,
86
- * n => `Value: ${n}`
87
- * )
88
- * ); // "Value: 5"
89
- * ```
90
- */
91
- Result.fold = (onErr, onOk) => (data) => Result.isOk(data) ? onOk(data.value) : onErr(data.error);
92
- /**
93
- * Pattern matches on a Result, returning the result of the matching case.
94
- *
95
- * @example
96
- * ```ts
97
- * pipe(
98
- * result,
99
- * Result.match({
100
- * ok: value => `Got ${value}`,
101
- * err: error => `Failed: ${error}`
102
- * })
103
- * );
104
- * ```
105
- */
106
- Result.match = (cases) => (data) => Result.isOk(data) ? cases.ok(data.value) : cases.err(data.error);
107
- /**
108
- * Returns the success value or a default value if the Result is an error.
109
- * The default is a thunk `() => B` — evaluated only when the Result is Err.
110
- * The default can be a different type, widening the result to `A | B`.
111
- *
112
- * @example
113
- * ```ts
114
- * pipe(Result.ok(5), Result.getOrElse(() => 0)); // 5
115
- * pipe(Result.err("error"), Result.getOrElse(() => 0)); // 0
116
- * pipe(Result.err("error"), Result.getOrElse(() => null)); // null — typed as number | null
117
- * ```
118
- */
119
- Result.getOrElse = (defaultValue) => (data) => Result.isOk(data) ? data.value : defaultValue();
120
- /**
121
- * Executes a side effect on the success value without changing the Result.
122
- * Useful for logging or debugging.
123
- *
124
- * @example
125
- * ```ts
126
- * pipe(
127
- * Result.ok(5),
128
- * Result.tap(n => console.log("Value:", n)),
129
- * Result.map(n => n * 2)
130
- * );
131
- * ```
132
- */
133
- Result.tap = (f) => (data) => {
134
- if (Result.isOk(data))
135
- f(data.value);
136
- return data;
137
- };
138
- /**
139
- * Recovers from an error by providing a fallback Result.
140
- * The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
141
- */
142
- Result.recover = (fallback) => (data) => Result.isOk(data) ? data : fallback(data.error);
143
- /**
144
- * Recovers from an error unless it matches the blocked error.
145
- * The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
146
- */
147
- Result.recoverUnless = (blockedErr, fallback) => (data) => Result.isErr(data) && data.error !== blockedErr ? fallback() : data;
148
- /**
149
- * Converts a Result to an Option.
150
- * Ok becomes Some, Err becomes None (the error is discarded).
151
- *
152
- * @example
153
- * ```ts
154
- * Result.toOption(Result.ok(42)); // Some(42)
155
- * Result.toOption(Result.err("oops")); // None
156
- * ```
157
- */
158
- Result.toOption = (data) => Result.isOk(data) ? Option_js_1.Option.some(data.value) : Option_js_1.Option.none();
159
- /**
160
- * Applies a function wrapped in an Result to a value wrapped in an Result.
161
- *
162
- * @example
163
- * ```ts
164
- * const add = (a: number) => (b: number) => a + b;
165
- * pipe(
166
- * Result.ok(add),
167
- * Result.ap(Result.ok(5)),
168
- * Result.ap(Result.ok(3))
169
- * ); // Ok(8)
170
- * ```
171
- */
172
- Result.ap = (arg) => (data) => Result.isOk(data) && Result.isOk(arg) ? Result.ok(data.value(arg.value)) : Result.isErr(data) ? data : arg;
173
- })(Result || (exports.Result = Result = {}));
@@ -1,184 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.State = void 0;
4
- var State;
5
- (function (State) {
6
- /**
7
- * Lifts a pure value into a State computation. The state passes through unchanged.
8
- *
9
- * @example
10
- * ```ts
11
- * State.run(10)(State.resolve(42)); // [42, 10] — value 42, state unchanged
12
- * ```
13
- */
14
- State.resolve = (value) => (s) => [value, s];
15
- /**
16
- * Produces the current state as the value, without modifying it.
17
- *
18
- * @example
19
- * ```ts
20
- * const readStack: State<string[], string[]> = State.get();
21
- * State.run(["a", "b"])(readStack); // [["a", "b"], ["a", "b"]]
22
- * ```
23
- */
24
- State.get = () => (s) => [s, s];
25
- /**
26
- * Reads a projection of the state without modifying it.
27
- * Equivalent to `pipe(State.get(), State.map(f))` but more direct.
28
- *
29
- * @example
30
- * ```ts
31
- * type AppState = { count: number; label: string };
32
- * const readCount: State<AppState, number> = State.gets(s => s.count);
33
- * State.run({ count: 5, label: "x" })(readCount); // [5, { count: 5, label: "x" }]
34
- * ```
35
- */
36
- State.gets = (f) => (s) => [f(s), s];
37
- /**
38
- * Replaces the current state with a new value. Produces no meaningful value.
39
- *
40
- * @example
41
- * ```ts
42
- * const reset: State<number, undefined> = State.put(0);
43
- * State.run(99)(reset); // [undefined, 0]
44
- * ```
45
- */
46
- State.put = (newState) => (_s) => [undefined, newState];
47
- /**
48
- * Applies a function to the current state to produce the next state.
49
- * Produces no meaningful value.
50
- *
51
- * @example
52
- * ```ts
53
- * const push = (item: string): State<string[], undefined> =>
54
- * State.modify(stack => [...stack, item]);
55
- *
56
- * State.run(["a"])(push("b")); // [undefined, ["a", "b"]]
57
- * ```
58
- */
59
- State.modify = (f) => (s) => [undefined, f(s)];
60
- /**
61
- * Transforms the value produced by a State computation.
62
- * The state transformation is unchanged.
63
- *
64
- * @example
65
- * ```ts
66
- * const readLength: State<string[], number> = pipe(
67
- * State.get<string[]>(),
68
- * State.map(stack => stack.length),
69
- * );
70
- *
71
- * State.run(["a", "b", "c"])(readLength); // [3, ["a", "b", "c"]]
72
- * ```
73
- */
74
- State.map = (f) => (st) => (s) => {
75
- const [a, s1] = st(s);
76
- return [f(a), s1];
77
- };
78
- /**
79
- * Sequences two State computations. The state output of the first is passed
80
- * as the state input to the second.
81
- *
82
- * Data-last — the first computation is the data being piped.
83
- *
84
- * @example
85
- * ```ts
86
- * const push = (item: string): State<string[], undefined> =>
87
- * State.modify(stack => [...stack, item]);
88
- *
89
- * const program = pipe(
90
- * push("a"),
91
- * State.chain(() => push("b")),
92
- * State.chain(() => State.get<string[]>()),
93
- * );
94
- *
95
- * State.evaluate([])(program); // ["a", "b"]
96
- * ```
97
- */
98
- State.chain = (f) => (st) => (s) => {
99
- const [a, s1] = st(s);
100
- return f(a)(s1);
101
- };
102
- /**
103
- * Applies a function wrapped in a State to a value wrapped in a State.
104
- * The function computation runs first; its output state is the input to the
105
- * argument computation.
106
- *
107
- * @example
108
- * ```ts
109
- * const addCounted = (n: number) => (m: number) => n + m;
110
- * const program = pipe(
111
- * State.resolve<number, typeof addCounted>(addCounted),
112
- * State.ap(State.gets((s: number) => s * 2)),
113
- * State.ap(State.gets((s: number) => s)),
114
- * );
115
- *
116
- * State.evaluate(3)(program); // 6 + 3 = 9
117
- * ```
118
- */
119
- State.ap = (arg) => (fn) => (s) => {
120
- const [f, s1] = fn(s);
121
- const [a, s2] = arg(s1);
122
- return [f(a), s2];
123
- };
124
- /**
125
- * Runs a side effect on the produced value without changing the State computation.
126
- *
127
- * @example
128
- * ```ts
129
- * pipe(
130
- * State.get<number>(),
131
- * State.tap(n => console.log("current:", n)),
132
- * State.chain(() => State.modify(n => n + 1)),
133
- * );
134
- * ```
135
- */
136
- State.tap = (f) => (st) => (s) => {
137
- const [a, s1] = st(s);
138
- f(a);
139
- return [a, s1];
140
- };
141
- /**
142
- * Runs a State computation with an initial state, returning both the
143
- * produced value and the final state as a pair.
144
- *
145
- * Data-last — the computation is the data being piped.
146
- *
147
- * @example
148
- * ```ts
149
- * const program = pipe(
150
- * State.modify<number>(n => n + 1),
151
- * State.chain(() => State.get<number>()),
152
- * );
153
- *
154
- * State.run(0)(program); // [1, 1]
155
- * ```
156
- */
157
- State.run = (initialState) => (st) => st(initialState);
158
- /**
159
- * Runs a State computation with an initial state, returning only the
160
- * produced value (discarding the final state).
161
- *
162
- * @example
163
- * ```ts
164
- * State.evaluate([])(pipe(
165
- * State.modify<string[]>(s => [...s, "x"]),
166
- * State.chain(() => State.get<string[]>()),
167
- * )); // ["x"]
168
- * ```
169
- */
170
- State.evaluate = (initialState) => (st) => st(initialState)[0];
171
- /**
172
- * Runs a State computation with an initial state, returning only the
173
- * final state (discarding the produced value).
174
- *
175
- * @example
176
- * ```ts
177
- * State.execute(0)(pipe(
178
- * State.modify<number>(n => n + 10),
179
- * State.chain(() => State.modify<number>(n => n * 2)),
180
- * )); // 20
181
- * ```
182
- */
183
- State.execute = (initialState) => (st) => st(initialState)[1];
184
- })(State || (exports.State = State = {}));