@nlozgachev/pipelined 0.12.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 (205) 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/Tuple.js +0 -112
  60. package/esm/src/Core/Validation.js +0 -212
  61. package/esm/src/Core/index.js +0 -18
  62. package/esm/src/Types/Brand.js +0 -28
  63. package/esm/src/Types/NonEmptyList.js +0 -14
  64. package/esm/src/Types/index.js +0 -2
  65. package/esm/src/Utils/Arr.js +0 -570
  66. package/esm/src/Utils/Dict.js +0 -421
  67. package/esm/src/Utils/Num.js +0 -124
  68. package/esm/src/Utils/Rec.js +0 -241
  69. package/esm/src/Utils/Str.js +0 -134
  70. package/esm/src/Utils/Uniq.js +0 -265
  71. package/esm/src/Utils/index.js +0 -6
  72. package/script/mod.js +0 -19
  73. package/script/package.json +0 -3
  74. package/script/src/Composition/compose.js +0 -6
  75. package/script/src/Composition/converge.js +0 -6
  76. package/script/src/Composition/curry.js +0 -48
  77. package/script/src/Composition/flip.js +0 -24
  78. package/script/src/Composition/flow.js +0 -11
  79. package/script/src/Composition/fn.js +0 -98
  80. package/script/src/Composition/index.js +0 -29
  81. package/script/src/Composition/juxt.js +0 -6
  82. package/script/src/Composition/memoize.js +0 -71
  83. package/script/src/Composition/not.js +0 -29
  84. package/script/src/Composition/on.js +0 -16
  85. package/script/src/Composition/pipe.js +0 -6
  86. package/script/src/Composition/tap.js +0 -37
  87. package/script/src/Composition/uncurry.js +0 -38
  88. package/script/src/Core/Deferred.js +0 -33
  89. package/script/src/Core/InternalTypes.js +0 -2
  90. package/script/src/Core/Lens.js +0 -101
  91. package/script/src/Core/Logged.js +0 -114
  92. package/script/src/Core/Option.js +0 -194
  93. package/script/src/Core/Optional.js +0 -163
  94. package/script/src/Core/Predicate.js +0 -136
  95. package/script/src/Core/Reader.js +0 -137
  96. package/script/src/Core/Refinement.js +0 -118
  97. package/script/src/Core/RemoteData.js +0 -214
  98. package/script/src/Core/Result.js +0 -173
  99. package/script/src/Core/State.js +0 -184
  100. package/script/src/Core/Task.js +0 -226
  101. package/script/src/Core/TaskOption.js +0 -109
  102. package/script/src/Core/TaskResult.js +0 -130
  103. package/script/src/Core/TaskValidation.js +0 -131
  104. package/script/src/Core/These.js +0 -248
  105. package/script/src/Core/Tuple.js +0 -115
  106. package/script/src/Core/Validation.js +0 -215
  107. package/script/src/Core/index.js +0 -34
  108. package/script/src/Types/Brand.js +0 -31
  109. package/script/src/Types/NonEmptyList.js +0 -18
  110. package/script/src/Types/index.js +0 -18
  111. package/script/src/Utils/Arr.js +0 -573
  112. package/script/src/Utils/Dict.js +0 -424
  113. package/script/src/Utils/Num.js +0 -127
  114. package/script/src/Utils/Rec.js +0 -244
  115. package/script/src/Utils/Str.js +0 -137
  116. package/script/src/Utils/Uniq.js +0 -268
  117. package/script/src/Utils/index.js +0 -22
  118. package/types/mod.d.ts +0 -4
  119. package/types/mod.d.ts.map +0 -1
  120. package/types/src/Composition/compose.d.ts +0 -33
  121. package/types/src/Composition/compose.d.ts.map +0 -1
  122. package/types/src/Composition/converge.d.ts +0 -21
  123. package/types/src/Composition/converge.d.ts.map +0 -1
  124. package/types/src/Composition/curry.d.ts +0 -43
  125. package/types/src/Composition/curry.d.ts.map +0 -1
  126. package/types/src/Composition/flip.d.ts +0 -21
  127. package/types/src/Composition/flip.d.ts.map +0 -1
  128. package/types/src/Composition/flow.d.ts +0 -56
  129. package/types/src/Composition/flow.d.ts.map +0 -1
  130. package/types/src/Composition/fn.d.ts +0 -76
  131. package/types/src/Composition/fn.d.ts.map +0 -1
  132. package/types/src/Composition/index.d.ts +0 -14
  133. package/types/src/Composition/index.d.ts.map +0 -1
  134. package/types/src/Composition/juxt.d.ts +0 -18
  135. package/types/src/Composition/juxt.d.ts.map +0 -1
  136. package/types/src/Composition/memoize.d.ts +0 -46
  137. package/types/src/Composition/memoize.d.ts.map +0 -1
  138. package/types/src/Composition/not.d.ts +0 -26
  139. package/types/src/Composition/not.d.ts.map +0 -1
  140. package/types/src/Composition/on.d.ts +0 -13
  141. package/types/src/Composition/on.d.ts.map +0 -1
  142. package/types/src/Composition/pipe.d.ts +0 -56
  143. package/types/src/Composition/pipe.d.ts.map +0 -1
  144. package/types/src/Composition/tap.d.ts +0 -31
  145. package/types/src/Composition/tap.d.ts.map +0 -1
  146. package/types/src/Composition/uncurry.d.ts +0 -54
  147. package/types/src/Composition/uncurry.d.ts.map +0 -1
  148. package/types/src/Core/Deferred.d.ts +0 -49
  149. package/types/src/Core/Deferred.d.ts.map +0 -1
  150. package/types/src/Core/InternalTypes.d.ts +0 -23
  151. package/types/src/Core/InternalTypes.d.ts.map +0 -1
  152. package/types/src/Core/Lens.d.ts +0 -118
  153. package/types/src/Core/Lens.d.ts.map +0 -1
  154. package/types/src/Core/Logged.d.ts +0 -126
  155. package/types/src/Core/Logged.d.ts.map +0 -1
  156. package/types/src/Core/Option.d.ts +0 -209
  157. package/types/src/Core/Option.d.ts.map +0 -1
  158. package/types/src/Core/Optional.d.ts +0 -158
  159. package/types/src/Core/Optional.d.ts.map +0 -1
  160. package/types/src/Core/Predicate.d.ts +0 -161
  161. package/types/src/Core/Predicate.d.ts.map +0 -1
  162. package/types/src/Core/Reader.d.ts +0 -156
  163. package/types/src/Core/Reader.d.ts.map +0 -1
  164. package/types/src/Core/Refinement.d.ts +0 -138
  165. package/types/src/Core/Refinement.d.ts.map +0 -1
  166. package/types/src/Core/RemoteData.d.ts +0 -197
  167. package/types/src/Core/RemoteData.d.ts.map +0 -1
  168. package/types/src/Core/Result.d.ts +0 -182
  169. package/types/src/Core/Result.d.ts.map +0 -1
  170. package/types/src/Core/State.d.ts +0 -192
  171. package/types/src/Core/State.d.ts.map +0 -1
  172. package/types/src/Core/Task.d.ts +0 -219
  173. package/types/src/Core/Task.d.ts.map +0 -1
  174. package/types/src/Core/TaskOption.d.ts +0 -121
  175. package/types/src/Core/TaskOption.d.ts.map +0 -1
  176. package/types/src/Core/TaskResult.d.ts +0 -119
  177. package/types/src/Core/TaskResult.d.ts.map +0 -1
  178. package/types/src/Core/TaskValidation.d.ts +0 -144
  179. package/types/src/Core/TaskValidation.d.ts.map +0 -1
  180. package/types/src/Core/These.d.ts +0 -225
  181. package/types/src/Core/These.d.ts.map +0 -1
  182. package/types/src/Core/Tuple.d.ts +0 -129
  183. package/types/src/Core/Tuple.d.ts.map +0 -1
  184. package/types/src/Core/Validation.d.ts +0 -203
  185. package/types/src/Core/Validation.d.ts.map +0 -1
  186. package/types/src/Core/index.d.ts +0 -19
  187. package/types/src/Core/index.d.ts.map +0 -1
  188. package/types/src/Types/Brand.d.ts.map +0 -1
  189. package/types/src/Types/NonEmptyList.d.ts.map +0 -1
  190. package/types/src/Types/index.d.ts +0 -3
  191. package/types/src/Types/index.d.ts.map +0 -1
  192. package/types/src/Utils/Arr.d.ts +0 -403
  193. package/types/src/Utils/Arr.d.ts.map +0 -1
  194. package/types/src/Utils/Dict.d.ts +0 -310
  195. package/types/src/Utils/Dict.d.ts.map +0 -1
  196. package/types/src/Utils/Num.d.ts +0 -110
  197. package/types/src/Utils/Num.d.ts.map +0 -1
  198. package/types/src/Utils/Rec.d.ts +0 -159
  199. package/types/src/Utils/Rec.d.ts.map +0 -1
  200. package/types/src/Utils/Str.d.ts +0 -128
  201. package/types/src/Utils/Str.d.ts.map +0 -1
  202. package/types/src/Utils/Uniq.d.ts +0 -179
  203. package/types/src/Utils/Uniq.d.ts.map +0 -1
  204. package/types/src/Utils/index.d.ts +0 -7
  205. package/types/src/Utils/index.d.ts.map +0 -1
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Refinement = void 0;
4
- const Option_js_1 = require("./Option.js");
5
- const Result_js_1 = require("./Result.js");
6
- var Refinement;
7
- (function (Refinement) {
8
- /**
9
- * Creates a `Refinement<A, B>` from a plain boolean predicate.
10
- *
11
- * This is an unsafe cast — the caller is responsible for ensuring that the
12
- * predicate truly characterises values of type `B`. Use this only when
13
- * bootstrapping a new refinement; prefer `compose`, `and`, or `or` to build
14
- * derived refinements from existing ones.
15
- *
16
- * @example
17
- * ```ts
18
- * type PositiveNumber = number & { readonly _tag: "PositiveNumber" };
19
- *
20
- * const isPositive: Refinement<number, PositiveNumber> =
21
- * Refinement.make(n => n > 0);
22
- * ```
23
- */
24
- Refinement.make = (f) => f;
25
- /**
26
- * Chains two refinements: if `ab` narrows `A` to `B` and `bc` narrows `B` to `C`,
27
- * the result narrows `A` directly to `C`.
28
- *
29
- * Data-last — the first refinement `ab` is the data being piped.
30
- *
31
- * @example
32
- * ```ts
33
- * type NonEmptyString = string & { readonly _tag: "NonEmpty" };
34
- * type TrimmedString = NonEmptyString & { readonly _tag: "Trimmed" };
35
- *
36
- * const isNonEmpty: Refinement<string, NonEmptyString> =
37
- * Refinement.make(s => s.length > 0);
38
- * const isTrimmed: Refinement<NonEmptyString, TrimmedString> =
39
- * Refinement.make(s => s === s.trim());
40
- *
41
- * const isNonEmptyTrimmed: Refinement<string, TrimmedString> = pipe(
42
- * isNonEmpty,
43
- * Refinement.compose(isTrimmed)
44
- * );
45
- * ```
46
- */
47
- Refinement.compose = (bc) => (ab) => (a) => ab(a) && bc(a);
48
- /**
49
- * Intersects two refinements: the result narrows `A` to `B & C`, passing only
50
- * when both refinements hold simultaneously.
51
- *
52
- * Data-last — the first refinement is the data being piped.
53
- *
54
- * @example
55
- * ```ts
56
- * const isString: Refinement<unknown, string> = Refinement.make(x => typeof x === "string");
57
- * const isNonEmpty: Refinement<unknown, { length: number }> =
58
- * Refinement.make(x => (x as any).length > 0);
59
- *
60
- * const isNonEmptyString = pipe(isString, Refinement.and(isNonEmpty));
61
- * isNonEmptyString("hi"); // true
62
- * isNonEmptyString(""); // false
63
- * ```
64
- */
65
- Refinement.and = (second) => (first) => (a) => first(a) && second(a);
66
- /**
67
- * Unions two refinements: the result narrows `A` to `B | C`, passing when either
68
- * refinement holds.
69
- *
70
- * Data-last — the first refinement is the data being piped.
71
- *
72
- * @example
73
- * ```ts
74
- * const isString: Refinement<unknown, string> = Refinement.make(x => typeof x === "string");
75
- * const isNumber: Refinement<unknown, number> = Refinement.make(x => typeof x === "number");
76
- *
77
- * const isStringOrNumber = pipe(isString, Refinement.or(isNumber));
78
- * isStringOrNumber("hi"); // true
79
- * isStringOrNumber(42); // true
80
- * isStringOrNumber(true); // false
81
- * ```
82
- */
83
- Refinement.or = (second) => (first) => (a) => first(a) || second(a);
84
- /**
85
- * Converts a `Refinement<A, B>` into a function `(a: A) => Option<B>`.
86
- *
87
- * Returns `Some(a)` when the refinement holds, `None` otherwise. Useful for
88
- * integrating runtime validation into an `Option`-based pipeline.
89
- *
90
- * @example
91
- * ```ts
92
- * type PositiveNumber = number & { readonly _tag: "Positive" };
93
- * const isPositive: Refinement<number, PositiveNumber> =
94
- * Refinement.make(n => n > 0);
95
- *
96
- * pipe(-1, Refinement.toFilter(isPositive)); // None
97
- * pipe(42, Refinement.toFilter(isPositive)); // Some(42)
98
- * ```
99
- */
100
- Refinement.toFilter = (r) => (a) => r(a) ? Option_js_1.Option.some(a) : Option_js_1.Option.none();
101
- /**
102
- * Converts a `Refinement<A, B>` into a function `(a: A) => Result<E, B>`.
103
- *
104
- * Returns `Ok(a)` when the refinement holds, `Err(onFail(a))` otherwise. Use
105
- * this to surface validation failures as typed errors inside a `Result` pipeline.
106
- *
107
- * @example
108
- * ```ts
109
- * type NonEmptyString = string & { readonly _tag: "NonEmpty" };
110
- * const isNonEmpty: Refinement<string, NonEmptyString> =
111
- * Refinement.make(s => s.length > 0);
112
- *
113
- * pipe("", Refinement.toResult(isNonEmpty, () => "must not be empty")); // Err(...)
114
- * pipe("hi", Refinement.toResult(isNonEmpty, () => "must not be empty")); // Ok("hi")
115
- * ```
116
- */
117
- Refinement.toResult = (r, onFail) => (a) => r(a) ? Result_js_1.Result.ok(a) : Result_js_1.Result.err(onFail(a));
118
- })(Refinement || (exports.Refinement = Refinement = {}));
@@ -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 = {}));