@satoshibits/functional 1.0.3 → 1.1.2

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 (134) hide show
  1. package/README.md +28 -145
  2. package/dist/array-utils.d.mts +13 -0
  3. package/dist/array-utils.d.mts.map +1 -1
  4. package/dist/array-utils.mjs +19 -3
  5. package/dist/array-utils.mjs.map +1 -1
  6. package/dist/array-utils.test.d.ts +2 -0
  7. package/dist/array-utils.test.d.ts.map +1 -0
  8. package/dist/array-utils.test.js +256 -0
  9. package/dist/array-utils.test.js.map +1 -0
  10. package/dist/composition.d.mts +53 -6
  11. package/dist/composition.d.mts.map +1 -1
  12. package/dist/composition.mjs +111 -22
  13. package/dist/composition.mjs.map +1 -1
  14. package/dist/composition.test.d.ts +2 -0
  15. package/dist/composition.test.d.ts.map +1 -0
  16. package/dist/composition.test.js +409 -0
  17. package/dist/composition.test.js.map +1 -0
  18. package/dist/index.d.mts +10 -5
  19. package/dist/index.d.mts.map +1 -1
  20. package/dist/index.mjs +10 -5
  21. package/dist/index.mjs.map +1 -1
  22. package/dist/integration.test.d.mts +2 -0
  23. package/dist/integration.test.d.mts.map +1 -0
  24. package/dist/integration.test.mjs +486 -0
  25. package/dist/integration.test.mjs.map +1 -0
  26. package/dist/io.d.mts +338 -0
  27. package/dist/io.d.mts.map +1 -0
  28. package/dist/io.mjs +389 -0
  29. package/dist/io.mjs.map +1 -0
  30. package/dist/io.test.d.mts +2 -0
  31. package/dist/io.test.d.mts.map +1 -0
  32. package/dist/io.test.mjs +373 -0
  33. package/dist/io.test.mjs.map +1 -0
  34. package/dist/laws.test.d.mts +2 -0
  35. package/dist/laws.test.d.mts.map +1 -0
  36. package/dist/laws.test.mjs +614 -0
  37. package/dist/laws.test.mjs.map +1 -0
  38. package/dist/object-utils.d.mts +11 -0
  39. package/dist/object-utils.d.mts.map +1 -1
  40. package/dist/object-utils.mjs +11 -0
  41. package/dist/object-utils.mjs.map +1 -1
  42. package/dist/object-utils.test.d.ts +2 -0
  43. package/dist/object-utils.test.d.ts.map +1 -0
  44. package/dist/object-utils.test.js +286 -0
  45. package/dist/object-utils.test.js.map +1 -0
  46. package/dist/option-additions.test.d.mts +2 -0
  47. package/dist/option-additions.test.d.mts.map +1 -0
  48. package/dist/option-additions.test.mjs +325 -0
  49. package/dist/option-additions.test.mjs.map +1 -0
  50. package/dist/option.d.mts +202 -58
  51. package/dist/option.d.mts.map +1 -1
  52. package/dist/option.mjs +271 -63
  53. package/dist/option.mjs.map +1 -1
  54. package/dist/option.test.d.ts +6 -0
  55. package/dist/option.test.d.ts.map +1 -0
  56. package/dist/option.test.js +606 -0
  57. package/dist/option.test.js.map +1 -0
  58. package/dist/performance.d.mts +27 -10
  59. package/dist/performance.d.mts.map +1 -1
  60. package/dist/performance.mjs +42 -20
  61. package/dist/performance.mjs.map +1 -1
  62. package/dist/performance.test.d.ts +2 -0
  63. package/dist/performance.test.d.ts.map +1 -0
  64. package/dist/performance.test.js +424 -0
  65. package/dist/performance.test.js.map +1 -0
  66. package/dist/pipeline.d.mts +12 -0
  67. package/dist/pipeline.d.mts.map +1 -1
  68. package/dist/pipeline.mjs +12 -0
  69. package/dist/pipeline.mjs.map +1 -1
  70. package/dist/pipeline.test.d.ts +2 -0
  71. package/dist/pipeline.test.d.ts.map +1 -0
  72. package/dist/pipeline.test.js +445 -0
  73. package/dist/pipeline.test.js.map +1 -0
  74. package/dist/predicates.d.mts +12 -0
  75. package/dist/predicates.d.mts.map +1 -1
  76. package/dist/predicates.mjs +12 -0
  77. package/dist/predicates.mjs.map +1 -1
  78. package/dist/predicates.test.d.ts +2 -0
  79. package/dist/predicates.test.d.ts.map +1 -0
  80. package/dist/predicates.test.js +375 -0
  81. package/dist/predicates.test.js.map +1 -0
  82. package/dist/reader-result.d.mts +37 -16
  83. package/dist/reader-result.d.mts.map +1 -1
  84. package/dist/reader-result.mjs +37 -16
  85. package/dist/reader-result.mjs.map +1 -1
  86. package/dist/reader-result.test.d.ts +2 -0
  87. package/dist/reader-result.test.d.ts.map +1 -0
  88. package/dist/reader-result.test.js +1259 -0
  89. package/dist/reader-result.test.js.map +1 -0
  90. package/dist/reader.d.mts +443 -0
  91. package/dist/reader.d.mts.map +1 -0
  92. package/dist/reader.mjs +456 -0
  93. package/dist/reader.mjs.map +1 -0
  94. package/dist/reader.test.d.mts +2 -0
  95. package/dist/reader.test.d.mts.map +1 -0
  96. package/dist/reader.test.mjs +288 -0
  97. package/dist/reader.test.mjs.map +1 -0
  98. package/dist/result-additions.test.d.mts +2 -0
  99. package/dist/result-additions.test.d.mts.map +1 -0
  100. package/dist/result-additions.test.mjs +325 -0
  101. package/dist/result-additions.test.mjs.map +1 -0
  102. package/dist/result.d.mts +208 -0
  103. package/dist/result.d.mts.map +1 -1
  104. package/dist/result.mjs +287 -0
  105. package/dist/result.mjs.map +1 -1
  106. package/dist/result.test.d.ts +2 -0
  107. package/dist/result.test.d.ts.map +1 -0
  108. package/dist/result.test.js +453 -0
  109. package/dist/result.test.js.map +1 -0
  110. package/dist/task.d.mts +374 -0
  111. package/dist/task.d.mts.map +1 -0
  112. package/dist/task.mjs +386 -0
  113. package/dist/task.mjs.map +1 -0
  114. package/dist/task.test.d.mts +2 -0
  115. package/dist/task.test.d.mts.map +1 -0
  116. package/dist/task.test.mjs +1006 -0
  117. package/dist/task.test.mjs.map +1 -0
  118. package/dist/types.d.mts +12 -0
  119. package/dist/types.d.mts.map +1 -1
  120. package/dist/types.mjs +12 -0
  121. package/dist/types.mjs.map +1 -1
  122. package/dist/types.test.d.ts +6 -0
  123. package/dist/types.test.d.ts.map +1 -0
  124. package/dist/types.test.js +447 -0
  125. package/dist/types.test.js.map +1 -0
  126. package/dist/validation.d.mts +12 -0
  127. package/dist/validation.d.mts.map +1 -1
  128. package/dist/validation.mjs +22 -4
  129. package/dist/validation.mjs.map +1 -1
  130. package/dist/validation.test.d.ts +2 -0
  131. package/dist/validation.test.d.ts.map +1 -0
  132. package/dist/validation.test.js +518 -0
  133. package/dist/validation.test.js.map +1 -0
  134. package/package.json +77 -13
@@ -0,0 +1,456 @@
1
+ "use strict";
2
+ /**
3
+ * @module reader
4
+ * @description Reader represents a computation with access to a shared environment/context.
5
+ * The Reader monad provides a way to compose functions that all depend on some shared
6
+ * configuration or dependency injection context, without having to pass it explicitly
7
+ * through every function call.
8
+ *
9
+ * ### For Dummies
10
+ * - A Reader is just a function that expects a bag of dependencies and gives you a result.
11
+ * - You describe what to do with the bag now and hand the bag in later, keeping tests simple.
12
+ * - No async, no error handling—think "grab config once you finally call me".
13
+ *
14
+ * ### Decision Tree
15
+ * - Need a starting value that ignores the environment? Use `Reader.of(value)`.
16
+ * - Want the full environment? `Reader.ask()` gives it to you; need a slice? Use `Reader.asks(selector)`.
17
+ * - Transforming a computed value without changing dependencies? Use `Reader.map(fn)`.
18
+ * - Need the next step to access the environment again? Use `Reader.chain(nextReader)`.
19
+ * - Done describing the program? Call `Reader.run(env)(program)` when you finally have the dependencies.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * import { Reader } from './reader.mts';
24
+ *
25
+ * // basic usage
26
+ * type Config = { apiUrl: string; timeout: number };
27
+ *
28
+ * const getApiUrl: Reader<Config, string> = config => config.apiUrl;
29
+ * const getTimeout: Reader<Config, number> = config => config.timeout;
30
+ *
31
+ * // composing readers
32
+ * const buildRequest = Reader.chain((url: string) =>
33
+ * Reader.map((timeout: number) => ({ url, timeout }))(getTimeout)
34
+ * )(getApiUrl);
35
+ *
36
+ * // running readers
37
+ * const config: Config = { apiUrl: 'https://api.example.com', timeout: 5000 };
38
+ * const request = Reader.run(config)(buildRequest);
39
+ * // => { url: 'https://api.example.com', timeout: 5000 }
40
+ * ```
41
+ *
42
+ * @category Core
43
+ * @since 2025-09-18
44
+ */
45
+ /**
46
+ * Reader utility functions for working with Reader types.
47
+ * @description Provides a functional API for creating, transforming, and composing Readers.
48
+ * All functions are curried to support functional composition and partial application.
49
+ *
50
+ * @category Utilities
51
+ * @since 2025-09-18
52
+ */
53
+ export var Reader = {
54
+ /**
55
+ * Creates a Reader that returns the given value, ignoring the environment.
56
+ * @description Factory function for creating Readers from values. The resulting
57
+ * Reader will always return the provided value regardless of the environment.
58
+ *
59
+ * @template R - The type of the environment
60
+ * @template A - The type of the value
61
+ * @param {A} value - The value to wrap in a Reader
62
+ * @returns {Reader<R, A>} A Reader that returns the value
63
+ *
64
+ * @category Constructors
65
+ * @example
66
+ * ```typescript
67
+ * const reader = Reader.of<Config, number>(42);
68
+ * Reader.run(config)(reader); // => 42
69
+ *
70
+ * // Useful for starting chains
71
+ * const result = Reader.run(config)(
72
+ * Reader.chain((n: number) => Reader.of<Config, number>(n * 2))(
73
+ * Reader.of<Config, number>(21)
74
+ * )
75
+ * ); // => 42
76
+ * ```
77
+ *
78
+ * @since 2025-09-18
79
+ */
80
+ of: function (value) { return function () { return value; }; },
81
+ /**
82
+ * Gets the current environment.
83
+ * @description Returns a Reader that provides access to the entire environment.
84
+ * This is the identity Reader for the environment type.
85
+ *
86
+ * @template R - The type of the environment
87
+ * @returns {Reader<R, R>} A Reader that returns the environment
88
+ *
89
+ * @category Environment
90
+ * @example
91
+ * ```typescript
92
+ * type Config = { port: number; host: string };
93
+ * const config: Config = { port: 3000, host: 'localhost' };
94
+ *
95
+ * const getConfig = Reader.ask<Config>();
96
+ * Reader.run(config)(getConfig); // => { port: 3000, host: 'localhost' }
97
+ * ```
98
+ *
99
+ * @since 2025-09-18
100
+ */
101
+ ask: function () { return function (deps) { return deps; }; },
102
+ /**
103
+ * Gets a value derived from the environment.
104
+ * @description Projects a value from the environment using a selector function.
105
+ * Useful for extracting specific parts of the environment.
106
+ *
107
+ * @template R - The type of the environment
108
+ * @template A - The type of the extracted value
109
+ * @param {function(R): A} f - Function to extract value from environment
110
+ * @returns {Reader<R, A>} A Reader that returns the extracted value
111
+ *
112
+ * @category Environment
113
+ * @example
114
+ * ```typescript
115
+ * type Config = { db: { host: string; port: number } };
116
+ *
117
+ * const getDbHost = Reader.asks<Config, string>(config => config.db.host);
118
+ * const config: Config = { db: { host: 'localhost', port: 5432 } };
119
+ * Reader.run(config)(getDbHost); // => 'localhost'
120
+ * ```
121
+ *
122
+ * @since 2025-09-18
123
+ */
124
+ asks: function (f) { return f; },
125
+ /**
126
+ * Transforms the value inside a Reader using the given function.
127
+ * @description Applies a pure function to the value produced by a Reader,
128
+ * creating a new Reader with the transformed value. This is the functor
129
+ * map operation for Reader types.
130
+ *
131
+ * @template R - The environment type
132
+ * @template A - The input type
133
+ * @template B - The output type
134
+ * @param {function(A): B} f - Function to transform the value
135
+ * @returns {function(Reader<R, A>): Reader<R, B>} A function that transforms Readers
136
+ *
137
+ * @category Transformations
138
+ * @example
139
+ * ```typescript
140
+ * type Config = { multiplier: number };
141
+ * const getValue: Reader<Config, number> = config => 10 * config.multiplier;
142
+ *
143
+ * const double = Reader.map((n: number) => n * 2);
144
+ * const doubled = double(getValue);
145
+ *
146
+ * const config: Config = { multiplier: 3 };
147
+ * Reader.run(config)(doubled); // => 60
148
+ * ```
149
+ *
150
+ * @since 2025-09-18
151
+ */
152
+ map: function (f) { return function (reader) {
153
+ return function (deps) { return f(reader(deps)); };
154
+ }; },
155
+ /**
156
+ * Chains Reader-returning operations.
157
+ * @description Sequences two Readers where the second depends on the result
158
+ * of the first. This is the monadic bind operation for Reader types.
159
+ *
160
+ * @template R - The environment type
161
+ * @template A - The input type
162
+ * @template B - The output type
163
+ * @param {function(A): Reader<R, B>} f - Function that returns a new Reader
164
+ * @returns {function(Reader<R, A>): Reader<R, B>} A function that chains Readers
165
+ *
166
+ * @category Combinators
167
+ * @example
168
+ * ```typescript
169
+ * type Config = { baseUrl: string; apiKey: string };
170
+ *
171
+ * const getBaseUrl: Reader<Config, string> = config => config.baseUrl;
172
+ * const buildEndpoint = (base: string): Reader<Config, string> =>
173
+ * config => `${base}/api?key=${config.apiKey}`;
174
+ *
175
+ * const getEndpoint = Reader.chain(buildEndpoint)(getBaseUrl);
176
+ *
177
+ * const config: Config = { baseUrl: 'https://api.com', apiKey: 'secret' };
178
+ * Reader.run(config)(getEndpoint); // => 'https://api.com/api?key=secret'
179
+ * ```
180
+ *
181
+ * @since 2025-09-18
182
+ */
183
+ chain: function (f) { return function (reader) {
184
+ return function (deps) { return f(reader(deps))(deps); };
185
+ }; },
186
+ /**
187
+ * Alias for chain to match fp-ts naming.
188
+ * @description See {@link chain} for details.
189
+ *
190
+ * @category Combinators
191
+ * @since 2025-09-18
192
+ */
193
+ flatMap: function (f) { return function (reader) {
194
+ return function (deps) { return f(reader(deps))(deps); };
195
+ }; },
196
+ /**
197
+ * Applies a Reader of a function to a Reader of a value.
198
+ * @description Enables applying functions wrapped in Readers to values wrapped
199
+ * in Readers. This is the applicative apply operation for Reader types.
200
+ *
201
+ * @template R - The environment type
202
+ * @template A - The input type
203
+ * @template B - The output type
204
+ * @param {Reader<R, A>} readerValue - Reader containing a value
205
+ * @returns {function(Reader<R, function(A): B>): Reader<R, B>} A function that applies Reader functions
206
+ *
207
+ * @category Combinators
208
+ * @example
209
+ * ```typescript
210
+ * type Config = { x: number; y: number };
211
+ *
212
+ * const add = (a: number) => (b: number) => a + b;
213
+ * const getX: Reader<Config, number> = config => config.x;
214
+ * const getY: Reader<Config, number> = config => config.y;
215
+ *
216
+ * const sum = Reader.ap(getY)(
217
+ * Reader.map(add)(getX)
218
+ * );
219
+ *
220
+ * const config: Config = { x: 5, y: 3 };
221
+ * Reader.run(config)(sum); // => 8
222
+ * ```
223
+ *
224
+ * @since 2025-09-18
225
+ */
226
+ ap: function (readerValue) { return function (readerFn) {
227
+ return function (deps) { return readerFn(deps)(readerValue(deps)); };
228
+ }; },
229
+ /**
230
+ * Runs a Reader with the given environment.
231
+ * @description Executes a Reader by providing it with the required environment,
232
+ * returning the computed value.
233
+ *
234
+ * @template R - The type of the environment
235
+ * @template A - The type of the value
236
+ * @param {R} deps - The environment to provide
237
+ * @returns {function(Reader<R, A>): A} A function that runs Readers
238
+ *
239
+ * @category Execution
240
+ * @example
241
+ * ```typescript
242
+ * type Config = { name: string };
243
+ * const getName: Reader<Config, string> = config => config.name;
244
+ *
245
+ * const config: Config = { name: 'Alice' };
246
+ * const name = Reader.run(config)(getName); // => 'Alice'
247
+ * ```
248
+ *
249
+ * @since 2025-09-18
250
+ */
251
+ run: function (deps) { return function (reader) { return reader(deps); }; },
252
+ /**
253
+ * Modifies the environment before running a Reader.
254
+ * @description Transforms the environment using a function before passing it
255
+ * to the Reader. This is contravariant mapping on the environment.
256
+ *
257
+ * @template R - The new environment type
258
+ * @template S - The original environment type
259
+ * @param {function(R): S} f - Function to transform the environment
260
+ * @returns {function(Reader<S, A>): Reader<R, A>} A function that adapts Readers
261
+ *
262
+ * @category Transformations
263
+ * @example
264
+ * ```typescript
265
+ * type AppConfig = { db: DbConfig; api: ApiConfig };
266
+ * type DbConfig = { host: string; port: number };
267
+ *
268
+ * const getDbHost: Reader<DbConfig, string> = config => config.host;
269
+ * const getAppDbHost = Reader.local<AppConfig, DbConfig>(
270
+ * app => app.db
271
+ * )(getDbHost);
272
+ *
273
+ * const appConfig: AppConfig = {
274
+ * db: { host: 'localhost', port: 5432 },
275
+ * api: { url: 'https://api.com' }
276
+ * };
277
+ * Reader.run(appConfig)(getAppDbHost); // => 'localhost'
278
+ * ```
279
+ *
280
+ * @since 2025-09-18
281
+ */
282
+ local: function (f) { return function (reader) {
283
+ return function (deps) { return reader(f(deps)); };
284
+ }; },
285
+ /**
286
+ * Converts an array of Readers into a Reader of an array.
287
+ * @description Sequences multiple Readers, collecting their results into an array.
288
+ *
289
+ * @template R - The environment type
290
+ * @template A - The type of values in the Readers
291
+ * @param {Reader<R, A>[]} readers - Array of Readers to sequence
292
+ * @returns {Reader<R, A[]>} A Reader containing an array of results
293
+ *
294
+ * @category Combinators
295
+ * @example
296
+ * ```typescript
297
+ * type Config = { x: number; y: number; z: number };
298
+ *
299
+ * const readers = [
300
+ * (c: Config) => c.x,
301
+ * (c: Config) => c.y,
302
+ * (c: Config) => c.z
303
+ * ];
304
+ * const combined = Reader.sequence(readers);
305
+ *
306
+ * const config: Config = { x: 1, y: 2, z: 3 };
307
+ * Reader.run(config)(combined); // => [1, 2, 3]
308
+ * ```
309
+ *
310
+ * @since 2025-09-18
311
+ */
312
+ sequence: function (readers) {
313
+ return function (deps) { return readers.map(function (reader) { return reader(deps); }); };
314
+ },
315
+ /**
316
+ * Maps a function returning a Reader over an array and sequences the results.
317
+ * @description Applies a Reader-returning function to each element of an array
318
+ * and collects all results.
319
+ *
320
+ * @template R - The environment type
321
+ * @template A - The input type
322
+ * @template B - The output type
323
+ * @param {function(A): Reader<R, B>} f - Function that returns a Reader
324
+ * @returns {function(A[]): Reader<R, B[]>} A function that traverses arrays with Readers
325
+ *
326
+ * @category Combinators
327
+ * @example
328
+ * ```typescript
329
+ * type Config = { multiplier: number };
330
+ *
331
+ * const multiplyBy = (n: number): Reader<Config, number> =>
332
+ * config => n * config.multiplier;
333
+ *
334
+ * const multiplyAll = Reader.traverse(multiplyBy);
335
+ * const results = multiplyAll([1, 2, 3]);
336
+ *
337
+ * const config: Config = { multiplier: 10 };
338
+ * Reader.run(config)(results); // => [10, 20, 30]
339
+ * ```
340
+ *
341
+ * @since 2025-09-18
342
+ */
343
+ traverse: function (f) { return function (as) {
344
+ return Reader.sequence(as.map(f));
345
+ }; },
346
+ /**
347
+ * Combines the results of a tuple of Readers into a Reader of a tuple.
348
+ * @description Takes multiple Readers and returns a Reader containing a tuple
349
+ * of their results.
350
+ *
351
+ * @template R - The environment type
352
+ * @template T - Tuple type of Readers
353
+ * @param {...T} readers - Readers to combine
354
+ * @returns {Reader<R, { [K in keyof T]: T[K] extends Reader<R, infer U> ? U : never }>} Reader of tuple
355
+ *
356
+ * @category Combinators
357
+ * @example
358
+ * ```typescript
359
+ * type Config = { name: string; age: number; active: boolean };
360
+ *
361
+ * const getName: Reader<Config, string> = c => c.name;
362
+ * const getAge: Reader<Config, number> = c => c.age;
363
+ * const getActive: Reader<Config, boolean> = c => c.active;
364
+ *
365
+ * const combined = Reader.sequenceT(getName, getAge, getActive);
366
+ *
367
+ * const config: Config = { name: 'Alice', age: 30, active: true };
368
+ * Reader.run(config)(combined); // => ['Alice', 30, true]
369
+ * ```
370
+ *
371
+ * @since 2025-09-18
372
+ */
373
+ sequenceT: function () {
374
+ var readers = [];
375
+ for (var _i = 0; _i < arguments.length; _i++) {
376
+ readers[_i] = arguments[_i];
377
+ }
378
+ return function (deps) { return readers.map(function (r) { return r(deps); }); };
379
+ },
380
+ /**
381
+ * Combines the results of a record of Readers into a Reader of a record.
382
+ * @description Takes an object with Reader values and returns a Reader containing
383
+ * an object with the results.
384
+ *
385
+ * @template R - The environment type
386
+ * @template S - Record type with Reader values
387
+ * @param {S} readers - Record of Readers to combine
388
+ * @returns {Reader<R, { [K in keyof S]: S[K] extends Reader<R, infer U> ? U : never }>} Reader of record
389
+ *
390
+ * @category Combinators
391
+ * @example
392
+ * ```typescript
393
+ * type Config = { user: string; host: string; port: number };
394
+ *
395
+ * const readers = {
396
+ * username: (c: Config) => c.user,
397
+ * server: (c: Config) => c.host,
398
+ * portNumber: (c: Config) => c.port
399
+ * };
400
+ *
401
+ * const combined = Reader.sequenceS(readers);
402
+ *
403
+ * const config: Config = { user: 'admin', host: 'localhost', port: 3000 };
404
+ * Reader.run(config)(combined);
405
+ * // => { username: 'admin', server: 'localhost', portNumber: 3000 }
406
+ * ```
407
+ *
408
+ * @since 2025-09-18
409
+ */
410
+ sequenceS: function (readers) {
411
+ return function (deps) {
412
+ var result = {};
413
+ for (var key in readers) {
414
+ if (Object.prototype.hasOwnProperty.call(readers, key)) {
415
+ result[key] = readers[key](deps);
416
+ }
417
+ }
418
+ return result;
419
+ };
420
+ },
421
+ /**
422
+ * Executes a Reader for its side effects, discarding the result.
423
+ * @description Runs a Reader-returning function but preserves the original value.
424
+ * Useful for logging or other side effects where the result isn't needed.
425
+ *
426
+ * @template R - The environment type
427
+ * @template A - The type of the value
428
+ * @param {function(A): Reader<R, any>} f - Function that returns a Reader (result discarded)
429
+ * @returns {function(Reader<R, A>): Reader<R, A>} A function that executes side effects
430
+ *
431
+ * @category Combinators
432
+ * @example
433
+ * ```typescript
434
+ * type Config = { logger: (msg: string) => void };
435
+ *
436
+ * const log = (msg: string): Reader<Config, void> =>
437
+ * config => config.logger(msg);
438
+ *
439
+ * const getValue: Reader<Config, number> = () => 42;
440
+ * const logged = Reader.chainFirst((n: number) => log(`Got: ${n}`))(getValue);
441
+ *
442
+ * const config: Config = { logger: console.log };
443
+ * Reader.run(config)(logged); // logs "Got: 42", returns 42
444
+ * ```
445
+ *
446
+ * @since 2025-09-18
447
+ */
448
+ chainFirst: function (f) { return function (reader) {
449
+ return function (deps) {
450
+ var a = reader(deps);
451
+ f(a)(deps);
452
+ return a;
453
+ };
454
+ }; },
455
+ };
456
+ //# sourceMappingURL=reader.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reader.mjs","sourceRoot":"","sources":["../src/reader.mts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AA2BH;;;;;;;GAOG;AACH,MAAM,CAAC,IAAM,MAAM,GAAG;IACpB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,EAAE,EAAE,UAAQ,KAAQ,IAAmB,OAAA,cAAM,OAAA,KAAK,EAAL,CAAK,EAAX,CAAW;IAElD;;;;;;;;;;;;;;;;;;;OAmBG;IACH,GAAG,EAAE,cAAwB,OAAA,UAAA,IAAI,IAAI,OAAA,IAAI,EAAJ,CAAI,EAAZ,CAAY;IAEzC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,IAAI,EAAE,UAAQ,CAAiB,IAAmB,OAAA,CAAC,EAAD,CAAC;IAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,GAAG,EAAE,UAAW,CAAkB,IAAK,OAAA,UAAC,MAAoB;QAC1D,OAAA,UAAA,IAAI,IAAI,OAAA,CAAC,CAA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AC,IAAI,CAAC,CAAC;YACvB,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACX,OAAO,CAAC,CAAC;QACX,CAAC;IAJD,CAIC,EALqD,CAKrD;CACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=reader.test.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reader.test.d.mts","sourceRoot":"","sources":["../src/reader.test.mts"],"names":[],"mappings":""}