@nlozgachev/pipelined 0.6.4 → 0.7.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 (60) hide show
  1. package/esm/src/Core/Logged.js +111 -0
  2. package/esm/src/Core/Option.js +4 -1
  3. package/esm/src/Core/Predicate.js +133 -0
  4. package/esm/src/Core/Refinement.js +115 -0
  5. package/esm/src/Core/RemoteData.js +3 -0
  6. package/esm/src/Core/Result.js +4 -0
  7. package/esm/src/Core/State.js +181 -0
  8. package/esm/src/Core/Task.js +36 -0
  9. package/esm/src/Core/TaskOption.js +1 -0
  10. package/esm/src/Core/TaskResult.js +2 -0
  11. package/esm/src/Core/TaskValidation.js +5 -1
  12. package/esm/src/Core/These.js +4 -0
  13. package/esm/src/Core/Validation.js +4 -0
  14. package/esm/src/Core/index.js +4 -0
  15. package/package.json +1 -1
  16. package/script/src/Core/Logged.js +114 -0
  17. package/script/src/Core/Option.js +4 -1
  18. package/script/src/Core/Predicate.js +136 -0
  19. package/script/src/Core/Refinement.js +118 -0
  20. package/script/src/Core/RemoteData.js +3 -0
  21. package/script/src/Core/Result.js +4 -0
  22. package/script/src/Core/State.js +184 -0
  23. package/script/src/Core/Task.js +36 -0
  24. package/script/src/Core/TaskOption.js +1 -0
  25. package/script/src/Core/TaskResult.js +2 -0
  26. package/script/src/Core/TaskValidation.js +5 -1
  27. package/script/src/Core/These.js +4 -0
  28. package/script/src/Core/Validation.js +4 -0
  29. package/script/src/Core/index.js +4 -0
  30. package/types/src/Composition/on.d.ts.map +1 -1
  31. package/types/src/Core/InternalTypes.d.ts +3 -0
  32. package/types/src/Core/InternalTypes.d.ts.map +1 -1
  33. package/types/src/Core/Logged.d.ts +126 -0
  34. package/types/src/Core/Logged.d.ts.map +1 -0
  35. package/types/src/Core/Option.d.ts +6 -3
  36. package/types/src/Core/Option.d.ts.map +1 -1
  37. package/types/src/Core/Predicate.d.ts +161 -0
  38. package/types/src/Core/Predicate.d.ts.map +1 -0
  39. package/types/src/Core/Refinement.d.ts +138 -0
  40. package/types/src/Core/Refinement.d.ts.map +1 -0
  41. package/types/src/Core/RemoteData.d.ts +5 -2
  42. package/types/src/Core/RemoteData.d.ts.map +1 -1
  43. package/types/src/Core/Result.d.ts +7 -3
  44. package/types/src/Core/Result.d.ts.map +1 -1
  45. package/types/src/Core/State.d.ts +192 -0
  46. package/types/src/Core/State.d.ts.map +1 -0
  47. package/types/src/Core/Task.d.ts +30 -0
  48. package/types/src/Core/Task.d.ts.map +1 -1
  49. package/types/src/Core/TaskOption.d.ts +2 -1
  50. package/types/src/Core/TaskOption.d.ts.map +1 -1
  51. package/types/src/Core/TaskResult.d.ts +4 -2
  52. package/types/src/Core/TaskResult.d.ts.map +1 -1
  53. package/types/src/Core/TaskValidation.d.ts +4 -2
  54. package/types/src/Core/TaskValidation.d.ts.map +1 -1
  55. package/types/src/Core/These.d.ts +6 -2
  56. package/types/src/Core/These.d.ts.map +1 -1
  57. package/types/src/Core/Validation.d.ts +7 -3
  58. package/types/src/Core/Validation.d.ts.map +1 -1
  59. package/types/src/Core/index.d.ts +4 -0
  60. package/types/src/Core/index.d.ts.map +1 -1
@@ -0,0 +1,184 @@
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 = {}));
@@ -162,6 +162,42 @@ var Task;
162
162
  });
163
163
  return run();
164
164
  });
165
+ /**
166
+ * Resolves with the value of the first Task to complete. All Tasks start
167
+ * immediately; the rest are abandoned once one resolves.
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * const fast = Task.from(() => new Promise<string>(r => setTimeout(() => r("fast"), 10)));
172
+ * const slow = Task.from(() => new Promise<string>(r => setTimeout(() => r("slow"), 200)));
173
+ *
174
+ * await Task.race([fast, slow])(); // "fast"
175
+ * ```
176
+ */
177
+ Task.race = (tasks) => Task.from(() => Promise.race(tasks.map(toPromise)));
178
+ /**
179
+ * Runs an array of Tasks one at a time in order, collecting all results.
180
+ * Each Task starts only after the previous one resolves.
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * let log: number[] = [];
185
+ * const makeTask = (n: number) => Task.from(() => {
186
+ * log.push(n);
187
+ * return Promise.resolve(n);
188
+ * });
189
+ *
190
+ * await Task.sequential([makeTask(1), makeTask(2), makeTask(3)])();
191
+ * // log = [1, 2, 3] — tasks ran in order
192
+ * ```
193
+ */
194
+ Task.sequential = (tasks) => Task.from(async () => {
195
+ const results = [];
196
+ for (const task of tasks) {
197
+ results.push(await toPromise(task));
198
+ }
199
+ return results;
200
+ });
165
201
  /**
166
202
  * Converts a `Task<A>` into a `Task<Result<E, A>>`, resolving to `Err` if the
167
203
  * Task does not complete within the given time.
@@ -82,6 +82,7 @@ var TaskOption;
82
82
  TaskOption.match = (cases) => (data) => Task_js_1.Task.map(Option_js_1.Option.match(cases))(data);
83
83
  /**
84
84
  * Returns the value or a default if the TaskOption resolves to None.
85
+ * The default can be a different type, widening the result to `Task<A | B>`.
85
86
  */
86
87
  TaskOption.getOrElse = (defaultValue) => (data) => Task_js_1.Task.map(Option_js_1.Option.getOrElse(defaultValue))(data);
87
88
  /**
@@ -53,10 +53,12 @@ var TaskResult;
53
53
  TaskResult.match = (cases) => (data) => Task_js_1.Task.map(Result_js_1.Result.match(cases))(data);
54
54
  /**
55
55
  * Recovers from an error by providing a fallback TaskResult.
56
+ * The fallback can produce a different success type, widening the result to `TaskResult<E, A | B>`.
56
57
  */
57
58
  TaskResult.recover = (fallback) => (data) => Task_js_1.Task.chain((result) => Result_js_1.Result.isErr(result) ? fallback(result.error) : Task_js_1.Task.resolve(result))(data);
58
59
  /**
59
60
  * Returns the success value or a default value if the TaskResult is an error.
61
+ * The default can be a different type, widening the result to `Task<A | B>`.
60
62
  */
61
63
  TaskResult.getOrElse = (defaultValue) => (data) => Task_js_1.Task.map(Result_js_1.Result.getOrElse(defaultValue))(data);
62
64
  /**
@@ -90,6 +90,7 @@ var TaskValidation;
90
90
  TaskValidation.match = (cases) => (data) => Task_js_1.Task.map(Validation_js_1.Validation.match(cases))(data);
91
91
  /**
92
92
  * Returns the success value or a default value if the TaskValidation is invalid.
93
+ * The default can be a different type, widening the result to `Task<A | B>`.
93
94
  */
94
95
  TaskValidation.getOrElse = (defaultValue) => (data) => Task_js_1.Task.map(Validation_js_1.Validation.getOrElse(defaultValue))(data);
95
96
  /**
@@ -99,6 +100,9 @@ var TaskValidation;
99
100
  TaskValidation.tap = (f) => (data) => Task_js_1.Task.map(Validation_js_1.Validation.tap(f))(data);
100
101
  /**
101
102
  * Recovers from an Invalid state by providing a fallback TaskValidation.
103
+ * The fallback can produce a different success type, widening the result to `TaskValidation<E, A | B>`.
102
104
  */
103
- TaskValidation.recover = (fallback) => (data) => Task_js_1.Task.chain((validation) => Validation_js_1.Validation.isValid(validation) ? Task_js_1.Task.resolve(validation) : fallback())(data);
105
+ TaskValidation.recover = (fallback) => (data) => Task_js_1.Task.chain((validation) => Validation_js_1.Validation.isValid(validation)
106
+ ? Task_js_1.Task.resolve(validation)
107
+ : fallback())(data);
104
108
  })(TaskValidation || (exports.TaskValidation = TaskValidation = {}));
@@ -187,23 +187,27 @@ var These;
187
187
  };
188
188
  /**
189
189
  * Returns the first value, or a default if the These has no first value.
190
+ * The default can be a different type, widening the result to `A | C`.
190
191
  *
191
192
  * @example
192
193
  * ```ts
193
194
  * pipe(These.first(5), These.getFirstOrElse(0)); // 5
194
195
  * pipe(These.both(5, "warn"), These.getFirstOrElse(0)); // 5
195
196
  * pipe(These.second("warn"), These.getFirstOrElse(0)); // 0
197
+ * pipe(These.second("warn"), These.getFirstOrElse(null)); // null — typed as number | null
196
198
  * ```
197
199
  */
198
200
  These.getFirstOrElse = (defaultValue) => (data) => These.hasFirst(data) ? data.first : defaultValue;
199
201
  /**
200
202
  * Returns the second value, or a default if the These has no second value.
203
+ * The default can be a different type, widening the result to `B | D`.
201
204
  *
202
205
  * @example
203
206
  * ```ts
204
207
  * pipe(These.second("warn"), These.getSecondOrElse("none")); // "warn"
205
208
  * pipe(These.both(5, "warn"), These.getSecondOrElse("none")); // "warn"
206
209
  * pipe(These.first(5), These.getSecondOrElse("none")); // "none"
210
+ * pipe(These.first(5), These.getSecondOrElse(null)); // null — typed as string | null
207
211
  * ```
208
212
  */
209
213
  These.getSecondOrElse = (defaultValue) => (data) => These.hasSecond(data) ? data.second : defaultValue;
@@ -135,11 +135,13 @@ var Validation;
135
135
  Validation.match = (cases) => (data) => Validation.isValid(data) ? cases.valid(data.value) : cases.invalid(data.errors);
136
136
  /**
137
137
  * Returns the success value or a default value if the Validation is invalid.
138
+ * The default can be a different type, widening the result to `A | B`.
138
139
  *
139
140
  * @example
140
141
  * ```ts
141
142
  * pipe(Validation.valid(5), Validation.getOrElse(0)); // 5
142
143
  * pipe(Validation.invalid("oops"), Validation.getOrElse(0)); // 0
144
+ * pipe(Validation.invalid("oops"), Validation.getOrElse(null)); // null — typed as number | null
143
145
  * ```
144
146
  */
145
147
  Validation.getOrElse = (defaultValue) => (data) => Validation.isValid(data) ? data.value : defaultValue;
@@ -162,10 +164,12 @@ var Validation;
162
164
  };
163
165
  /**
164
166
  * Recovers from an Invalid state by providing a fallback Validation.
167
+ * The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
165
168
  */
166
169
  Validation.recover = (fallback) => (data) => Validation.isValid(data) ? data : fallback();
167
170
  /**
168
171
  * Recovers from an Invalid state unless the errors contain any of the blocked errors.
172
+ * The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
169
173
  */
170
174
  Validation.recoverUnless = (blockedErrors, fallback) => (data) => Validation.isInvalid(data) &&
171
175
  !data.errors.some((err) => blockedErrors.includes(err))
@@ -15,13 +15,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./Arr.js"), exports);
18
+ __exportStar(require("./Logged.js"), exports);
18
19
  __exportStar(require("./Deferred.js"), exports);
19
20
  __exportStar(require("./Lens.js"), exports);
20
21
  __exportStar(require("./Option.js"), exports);
21
22
  __exportStar(require("./Reader.js"), exports);
22
23
  __exportStar(require("./Optional.js"), exports);
23
24
  __exportStar(require("./Rec.js"), exports);
25
+ __exportStar(require("./Predicate.js"), exports);
26
+ __exportStar(require("./Refinement.js"), exports);
24
27
  __exportStar(require("./RemoteData.js"), exports);
28
+ __exportStar(require("./State.js"), exports);
25
29
  __exportStar(require("./Result.js"), exports);
26
30
  __exportStar(require("./Task.js"), exports);
27
31
  __exportStar(require("./TaskOption.js"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"on.d.ts","sourceRoot":"","sources":["../../../src/src/Composition/on.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,EAAE,GACZ,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAC/C,GAAG,CAAC,EAAE,GAAG,CAAC,KAAG,CACC,CAAC"}
1
+ {"version":3,"file":"on.d.ts","sourceRoot":"","sources":["../../../src/src/Composition/on.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,EAAE,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,CAAC,KAAG,CACtE,CAAC"}
@@ -17,4 +17,7 @@ export type WithFirst<T> = {
17
17
  export type WithSecond<T> = {
18
18
  readonly second: T;
19
19
  };
20
+ export type WithLog<T> = {
21
+ readonly log: ReadonlyArray<T>;
22
+ };
20
23
  //# sourceMappingURL=InternalTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"InternalTypes.d.ts","sourceRoot":"","sources":["../../../src/src/Core/InternalTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI;IAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC;AAE9D,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjD,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjD,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;AAEjE,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjD,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC"}
1
+ {"version":3,"file":"InternalTypes.d.ts","sourceRoot":"","sources":["../../../src/src/Core/InternalTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI;IAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC;AAE9D,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjD,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjD,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;AAEjE,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjD,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC;AAEnD,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC"}
@@ -0,0 +1,126 @@
1
+ import { WithLog, WithValue } from "./InternalTypes.js";
2
+ /**
3
+ * A value paired with an accumulated log.
4
+ *
5
+ * `Logged<W, A>` pairs a result `A` with a sequence of log entries `W`. When
6
+ * you sequence two `Logged` computations with `chain`, the logs are
7
+ * automatically concatenated — you never have to thread the log array through
8
+ * your code manually.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const program = pipe(
13
+ * Logged.make<string, number>(0),
14
+ * Logged.chain(n => pipe(
15
+ * Logged.tell("start"),
16
+ * Logged.map(() => n + 1),
17
+ * )),
18
+ * Logged.chain(n => pipe(
19
+ * Logged.tell("done"),
20
+ * Logged.map(() => n * 10),
21
+ * )),
22
+ * );
23
+ *
24
+ * Logged.run(program); // [10, ["start", "done"]]
25
+ * ```
26
+ */
27
+ export type Logged<L, A> = WithValue<A> & WithLog<L>;
28
+ export declare namespace Logged {
29
+ /**
30
+ * Wraps a pure value into a `Logged` with an empty log.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * Logged.make<string, number>(42); // { value: 42, log: [] }
35
+ * ```
36
+ */
37
+ const make: <W, A>(value: A) => Logged<W, A>;
38
+ /**
39
+ * Creates a `Logged` that records a single log entry and produces no
40
+ * meaningful value. Use this to append to the log inside a `chain`.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * Logged.tell("operation completed"); // { value: undefined, log: ["operation completed"] }
45
+ * ```
46
+ */
47
+ const tell: <W>(entry: W) => Logged<W, undefined>;
48
+ /**
49
+ * Transforms the value inside a `Logged` without affecting the log.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * pipe(
54
+ * Logged.of<string, number>(5),
55
+ * Logged.map(n => n * 2),
56
+ * ); // { value: 10, log: [] }
57
+ * ```
58
+ */
59
+ const map: <W, A, B>(f: (a: A) => B) => (data: Logged<W, A>) => Logged<W, B>;
60
+ /**
61
+ * Sequences two `Logged` computations, concatenating their logs.
62
+ * The value from the first is passed to `f`; the resulting log entries are
63
+ * appended after the entries from the first.
64
+ *
65
+ * Data-last — the first computation is the data being piped.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * const result = pipe(
70
+ * Logged.of<string, number>(1),
71
+ * Logged.chain(n => pipe(Logged.tell("step"), Logged.map(() => n + 1))),
72
+ * Logged.chain(n => pipe(Logged.tell("done"), Logged.map(() => n * 10))),
73
+ * );
74
+ *
75
+ * Logged.run(result); // [20, ["step", "done"]]
76
+ * ```
77
+ */
78
+ const chain: <W, A, B>(f: (a: A) => Logged<W, B>) => (data: Logged<W, A>) => Logged<W, B>;
79
+ /**
80
+ * Applies a function wrapped in a `Logged` to a value wrapped in a `Logged`,
81
+ * concatenating both logs.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * const fn: Logged<string, (n: number) => number> = {
86
+ * value: n => n * 2,
87
+ * log: ["fn-loaded"],
88
+ * };
89
+ * const arg: Logged<string, number> = { value: 5, log: ["arg-loaded"] };
90
+ *
91
+ * const result = pipe(fn, Logged.ap(arg));
92
+ * Logged.run(result); // [10, ["fn-loaded", "arg-loaded"]]
93
+ * ```
94
+ */
95
+ const ap: <W, A>(arg: Logged<W, A>) => <B>(data: Logged<W, (a: A) => B>) => Logged<W, B>;
96
+ /**
97
+ * Runs a side effect on the value without changing the `Logged`.
98
+ * Useful for debugging or inspecting intermediate values.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * pipe(
103
+ * Logged.of<string, number>(42),
104
+ * Logged.tap(n => console.log("value:", n)),
105
+ * );
106
+ * ```
107
+ */
108
+ const tap: <W, A>(f: (a: A) => void) => (data: Logged<W, A>) => Logged<W, A>;
109
+ /**
110
+ * Extracts the value and log as a `readonly [A, ReadonlyArray<W>]` tuple.
111
+ * Use this at the boundary where you need to consume both.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * const result = pipe(
116
+ * Logged.of<string, number>(1),
117
+ * Logged.chain(n => pipe(Logged.tell("incremented"), Logged.map(() => n + 1))),
118
+ * );
119
+ *
120
+ * const [value, log] = Logged.run(result);
121
+ * // value = 2, log = ["incremented"]
122
+ * ```
123
+ */
124
+ const run: <W, A>(data: Logged<W, A>) => readonly [A, ReadonlyArray<W>];
125
+ }
126
+ //# sourceMappingURL=Logged.d.ts.map
@@ -0,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CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAGzE,CAAC;IAEL;;;;;;;;;;;OAWG;IACI,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAGhF,CAAC;IAEF;;;;;;;;;;;;;;OAcG;IACI,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EACtB,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KACjB,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAA2B,CAAC;CAC7D"}
@@ -149,15 +149,17 @@ export declare namespace Option {
149
149
  some: (a: A) => B;
150
150
  }) => (data: Option<A>) => B;
151
151
  /**
152
- * Returns the value inside a Option, or a default value if None.
152
+ * Returns the value inside an Option, or a default value if None.
153
+ * The default can be a different type, widening the result to `A | B`.
153
154
  *
154
155
  * @example
155
156
  * ```ts
156
157
  * pipe(Option.some(5), Option.getOrElse(0)); // 5
157
158
  * pipe(Option.none(), Option.getOrElse(0)); // 0
159
+ * pipe(Option.none<string>(), Option.getOrElse(null)); // null — typed as string | null
158
160
  * ```
159
161
  */
160
- const getOrElse: <A>(defaultValue: A) => (data: Option<A>) => A;
162
+ const getOrElse: <A, B>(defaultValue: B) => (data: Option<A>) => A | B;
161
163
  /**
162
164
  * Executes a side effect on the value without changing the Option.
163
165
  * Useful for logging or debugging.
@@ -185,8 +187,9 @@ export declare namespace Option {
185
187
  const filter: <A>(predicate: (a: A) => boolean) => (data: Option<A>) => Option<A>;
186
188
  /**
187
189
  * Recovers from a None by providing a fallback Option.
190
+ * The fallback can produce a different type, widening the result to `Option<A | B>`.
188
191
  */
189
- const recover: <A>(fallback: () => Option<A>) => (data: Option<A>) => Option<A>;
192
+ const recover: <A, B>(fallback: () => Option<B>) => (data: Option<A>) => Option<A | B>;
190
193
  /**
191
194
  * Applies a function wrapped in a Option to a value wrapped in a Option.
192
195
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Option.d.ts","sourceRoot":"","sources":["../../../src/src/Core/Option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AAEvC,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AACtD,MAAM,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AAEpC,yBAAiB,MAAM,CAAC;IACtB;;OAEG;IACI,MAAM,IAAI,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,IAAI,CAAC,CAAC,CAA8B,CAAC;IAExE;;OAEG;IACI,MAAM,MAAM,GAAI,CAAC,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC,KAAG,IAAI,IAAI,IAAI,CAAC,CAAC,CAAyB,CAAC;IAEpF;;OAEG;IACI,MAAM,IAAI,QAAO,IAA0B,CAAC;IAEnD;;OAEG;IACI,MAAM,MAAM,GAAI,CAAC,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC,KAAG,IAAI,IAAI,IAA4B,CAAC;IAEjF;;;;;;;;;OASG;IACI,MAAM,YAAY,GAAI,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,KAAG,MAAM,CAAC,CAAC,CACR,CAAC;IAE/D;;OAEG;IACI,MAAM,UAAU,GAAI,CAAC,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC,KAAG,CAAC,GAAG,IAAwC,CAAC;IAE7F;;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