@nicolastoulemont/std 0.1.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 (94) hide show
  1. package/README.md +1 -0
  2. package/dist/adt/index.d.mts +2 -0
  3. package/dist/adt/index.mjs +3 -0
  4. package/dist/adt-DraJkmij.mjs +318 -0
  5. package/dist/adt-DraJkmij.mjs.map +1 -0
  6. package/dist/apply-fn.types-CXDoeA7D.d.mts +8 -0
  7. package/dist/apply-fn.types-CXDoeA7D.d.mts.map +1 -0
  8. package/dist/brand/index.d.mts +2 -0
  9. package/dist/brand/index.mjs +3 -0
  10. package/dist/brand-CTaxGuU9.mjs +165 -0
  11. package/dist/brand-CTaxGuU9.mjs.map +1 -0
  12. package/dist/data/index.d.mts +2 -0
  13. package/dist/data/index.mjs +3 -0
  14. package/dist/data-DgzWI4R_.mjs +244 -0
  15. package/dist/data-DgzWI4R_.mjs.map +1 -0
  16. package/dist/discriminator.types-DCkkrCj4.d.mts +7 -0
  17. package/dist/discriminator.types-DCkkrCj4.d.mts.map +1 -0
  18. package/dist/either/index.d.mts +2 -0
  19. package/dist/either/index.mjs +3 -0
  20. package/dist/either-CnOBUH7a.mjs +598 -0
  21. package/dist/either-CnOBUH7a.mjs.map +1 -0
  22. package/dist/equality/index.d.mts +86 -0
  23. package/dist/equality/index.d.mts.map +1 -0
  24. package/dist/equality/index.mjs +3 -0
  25. package/dist/equality-YMebYwm1.mjs +201 -0
  26. package/dist/equality-YMebYwm1.mjs.map +1 -0
  27. package/dist/err/index.d.mts +2 -0
  28. package/dist/err/index.mjs +3 -0
  29. package/dist/err-BqQApH9r.mjs +169 -0
  30. package/dist/err-BqQApH9r.mjs.map +1 -0
  31. package/dist/flow/index.d.mts +2 -0
  32. package/dist/flow/index.mjs +3 -0
  33. package/dist/flow-pRdnqmMY.mjs +21 -0
  34. package/dist/flow-pRdnqmMY.mjs.map +1 -0
  35. package/dist/gen/index.d.mts +3 -0
  36. package/dist/gen/index.mjs +3 -0
  37. package/dist/gen-YfMC9sDT.mjs +42 -0
  38. package/dist/gen-YfMC9sDT.mjs.map +1 -0
  39. package/dist/index-BCrD3pEs.d.mts +222 -0
  40. package/dist/index-BCrD3pEs.d.mts.map +1 -0
  41. package/dist/index-BR7takNf.d.mts +186 -0
  42. package/dist/index-BR7takNf.d.mts.map +1 -0
  43. package/dist/index-CcPnhWje.d.mts +72 -0
  44. package/dist/index-CcPnhWje.d.mts.map +1 -0
  45. package/dist/index-CtJ8Ks9X.d.mts +105 -0
  46. package/dist/index-CtJ8Ks9X.d.mts.map +1 -0
  47. package/dist/index-CvGTIg9L.d.mts +211 -0
  48. package/dist/index-CvGTIg9L.d.mts.map +1 -0
  49. package/dist/index-DPVT0yK4.d.mts +50 -0
  50. package/dist/index-DPVT0yK4.d.mts.map +1 -0
  51. package/dist/index-DgOAEEpu.d.mts +79 -0
  52. package/dist/index-DgOAEEpu.d.mts.map +1 -0
  53. package/dist/index-Dtq3kmln.d.mts +394 -0
  54. package/dist/index-Dtq3kmln.d.mts.map +1 -0
  55. package/dist/index-bLRqTe5I.d.mts +80 -0
  56. package/dist/index-bLRqTe5I.d.mts.map +1 -0
  57. package/dist/index-tkgTLCoq.d.mts +80 -0
  58. package/dist/index-tkgTLCoq.d.mts.map +1 -0
  59. package/dist/index-wTrnFgYg.d.mts +57 -0
  60. package/dist/index-wTrnFgYg.d.mts.map +1 -0
  61. package/dist/index-yyBTq8Ys.d.mts +79 -0
  62. package/dist/index-yyBTq8Ys.d.mts.map +1 -0
  63. package/dist/index.d.mts +135 -0
  64. package/dist/index.d.mts.map +1 -0
  65. package/dist/index.mjs +41 -0
  66. package/dist/index.mjs.map +1 -0
  67. package/dist/is-promise-BEl3eGZg.mjs +11 -0
  68. package/dist/is-promise-BEl3eGZg.mjs.map +1 -0
  69. package/dist/option/index.d.mts +3 -0
  70. package/dist/option/index.mjs +3 -0
  71. package/dist/option-CKHDOVea.mjs +410 -0
  72. package/dist/option-CKHDOVea.mjs.map +1 -0
  73. package/dist/option.types-D6TYG_i3.d.mts +89 -0
  74. package/dist/option.types-D6TYG_i3.d.mts.map +1 -0
  75. package/dist/pipe/index.d.mts +2 -0
  76. package/dist/pipe/index.mjs +3 -0
  77. package/dist/pipe-GYxZNkPB.mjs +10 -0
  78. package/dist/pipe-GYxZNkPB.mjs.map +1 -0
  79. package/dist/predicate/index.d.mts +2 -0
  80. package/dist/predicate/index.mjs +3 -0
  81. package/dist/predicate-B6-EdVgW.mjs +293 -0
  82. package/dist/predicate-B6-EdVgW.mjs.map +1 -0
  83. package/dist/result/index.d.mts +3 -0
  84. package/dist/result/index.mjs +3 -0
  85. package/dist/result-C5tPWR60.mjs +422 -0
  86. package/dist/result-C5tPWR60.mjs.map +1 -0
  87. package/dist/result-D7XJ96pv.mjs +1 -0
  88. package/dist/result.types-Ce7AEOzj.d.mts +156 -0
  89. package/dist/result.types-Ce7AEOzj.d.mts.map +1 -0
  90. package/dist/run/index.d.mts +2 -0
  91. package/dist/run/index.mjs +3 -0
  92. package/dist/run-DpXkImo9.mjs +10 -0
  93. package/dist/run-DpXkImo9.mjs.map +1 -0
  94. package/package.json +89 -0
@@ -0,0 +1,410 @@
1
+ import { t as isPromise } from "./is-promise-BEl3eGZg.mjs";
2
+
3
+ //#region src/option/option.types.ts
4
+ /**
5
+ * Singleton None value.
6
+ */
7
+ const None = { __typename: "None" };
8
+
9
+ //#endregion
10
+ //#region src/option/option.ts
11
+ /**
12
+ * Create an Option with a value.
13
+ *
14
+ * @param value - The value to wrap
15
+ * @returns An Option with some: true
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * some(42) // { some: true, value: 42 }
20
+ * ```
21
+ */
22
+ const some = (value) => ({
23
+ some: true,
24
+ value,
25
+ *[Symbol.iterator]() {
26
+ return value;
27
+ }
28
+ });
29
+ /**
30
+ * Create an Option with no value.
31
+ *
32
+ * @returns An Option with some: false
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * none() // { some: false }
37
+ * ```
38
+ */
39
+ const none = () => ({
40
+ some: false,
41
+ *[Symbol.iterator]() {
42
+ yield None;
43
+ throw new Error("Unreachable: Do should short-circuit on None");
44
+ }
45
+ });
46
+ /**
47
+ * Check if an Option has a value.
48
+ *
49
+ * @param option - The Option to check
50
+ * @returns true if the Option is some
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const option = some(42)
55
+ * if (isSome(option)) {
56
+ * console.log(option.value) // TypeScript knows value exists
57
+ * }
58
+ * ```
59
+ */
60
+ const isSome = (option) => option.some;
61
+ /**
62
+ * Check if an Option has no value.
63
+ *
64
+ * @param option - The Option to check
65
+ * @returns true if the Option is none
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * const option = none()
70
+ * if (isNone(option)) {
71
+ * console.log('No value') // TypeScript knows value doesn't exist
72
+ * }
73
+ * ```
74
+ */
75
+ const isNone = (option) => !option.some;
76
+ /**
77
+ * Transform the value of an Option.
78
+ * If the Option is none, it passes through unchanged.
79
+ *
80
+ * Supports both sync and async functions:
81
+ * - Sync fn: returns Option<U>
82
+ * - Async fn: returns Promise<Option<U>>
83
+ *
84
+ * @param fn - Function to transform the value
85
+ * @returns A function that takes an Option and returns a new Option
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * // Sync usage
90
+ * pipe(
91
+ * some(5),
92
+ * map(n => n * 2)
93
+ * ) // { some: true, value: 10 }
94
+ *
95
+ * // Async usage
96
+ * await pipe(
97
+ * some(userId),
98
+ * map(async id => await fetchName(id))
99
+ * ) // Promise<Option<string>>
100
+ * ```
101
+ */
102
+ const map = (fn) => (option) => {
103
+ if (!option.some) return option;
104
+ const mapped = fn(option.value);
105
+ if (mapped instanceof Promise) return mapped.then(some);
106
+ return some(mapped);
107
+ };
108
+ /**
109
+ * Chain operations that return Options.
110
+ * If the Option is none, it passes through unchanged.
111
+ *
112
+ * Supports both sync and async functions:
113
+ * - Sync fn: returns Option<U>
114
+ * - Async fn: returns Promise<Option<U>>
115
+ *
116
+ * @param fn - Function that takes a value and returns an Option (or Promise<Option>)
117
+ * @returns A function that takes an Option and returns a new Option
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * const findUser = (id: number) =>
122
+ * id > 0 ? some({ id, name: 'Alice' }) : none()
123
+ *
124
+ * // Sync usage
125
+ * pipe(
126
+ * some(10),
127
+ * flatMap(id => findUser(id))
128
+ * ) // { some: true, value: { id: 10, name: 'Alice' } }
129
+ *
130
+ * // Async usage
131
+ * await pipe(
132
+ * some(userId),
133
+ * flatMap(async id => some(await fetchUser(id)))
134
+ * ) // Promise<Option<User>>
135
+ * ```
136
+ */
137
+ const flatMap = (fn) => (option) => option.some ? fn(option.value) : option;
138
+ /**
139
+ * Perform a side effect on the value without modifying the Option.
140
+ * Useful for debugging, logging, or other side effects in a pipeline.
141
+ * If the Option is none, the function is not called.
142
+ *
143
+ * Supports both sync and async functions:
144
+ * - Sync fn: returns Option<T>
145
+ * - Async fn: returns Promise<Option<T>>
146
+ *
147
+ * @param fn - Function to call with the value (return value is ignored)
148
+ * @returns A function that takes an Option and returns the same Option
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * // Sync usage
153
+ * pipe(
154
+ * some(42),
155
+ * tap(console.log), // logs 42
156
+ * map(n => n * 2)
157
+ * ) // { some: true, value: 84 }
158
+ *
159
+ * // Async usage
160
+ * await pipe(
161
+ * some(42),
162
+ * tap(async v => await logToServer(v)),
163
+ * map(n => n * 2)
164
+ * ) // Promise<Option<84>>
165
+ * ```
166
+ */
167
+ const tap = (fn) => (option) => {
168
+ if (!option.some) return option;
169
+ const sideEffect = fn(option.value);
170
+ if (sideEffect instanceof Promise) return sideEffect.then(() => option);
171
+ return option;
172
+ };
173
+ /**
174
+ * Recover from none by providing an alternative Option.
175
+ * If the Option is some, it passes through unchanged.
176
+ *
177
+ * Supports both sync and async functions:
178
+ * - Sync fn: returns Option<T | U>
179
+ * - Async fn: returns Promise<Option<T | U>>
180
+ *
181
+ * @param fn - Function that returns an alternative Option
182
+ * @returns A function that takes an Option and returns a new Option
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * // Sync recovery
187
+ * pipe(
188
+ * none(),
189
+ * orElse(() => some(defaultValue))
190
+ * ) // { some: true, value: defaultValue }
191
+ *
192
+ * // Async recovery
193
+ * await pipe(
194
+ * none(),
195
+ * orElse(async () => some(await fetchFromAPI()))
196
+ * ) // Promise<Option<T>>
197
+ *
198
+ * // Chain multiple fallbacks
199
+ * pipe(
200
+ * none(),
201
+ * orElse(() => tryCache()),
202
+ * orElse(() => tryAPI()),
203
+ * orElse(() => some(fallback))
204
+ * )
205
+ * ```
206
+ */
207
+ const orElse = (fn) => (option) => option.some ? option : fn();
208
+ /**
209
+ * Filter an Option based on a predicate.
210
+ * If the predicate returns false, converts to none.
211
+ * If the Option is already none, it passes through unchanged.
212
+ *
213
+ * @param predicate - Function that returns true to keep the value
214
+ * @returns A function that takes an Option and returns a new Option
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * pipe(
219
+ * some(5),
220
+ * filter(n => n > 10)
221
+ * ) // { some: false }
222
+ *
223
+ * pipe(
224
+ * some(15),
225
+ * filter(n => n > 10)
226
+ * ) // { some: true, value: 15 }
227
+ *
228
+ * // With complex validation
229
+ * pipe(
230
+ * some(user),
231
+ * filter(u => u.age >= 18)
232
+ * )
233
+ * ```
234
+ */
235
+ const filter = (predicate) => (option) => {
236
+ if (!option.some) return option;
237
+ return predicate(option.value) ? option : none();
238
+ };
239
+ function all(options) {
240
+ if (Array.isArray(options)) {
241
+ const values$1 = [];
242
+ for (const option of options) {
243
+ if (!option.some) return option;
244
+ values$1.push(option.value);
245
+ }
246
+ return some(values$1);
247
+ }
248
+ const values = {};
249
+ for (const [key, option] of Object.entries(options)) {
250
+ const o = option;
251
+ if (!o.some) return option;
252
+ values[key] = o.value;
253
+ }
254
+ return some(values);
255
+ }
256
+ /**
257
+ * Get the value or a default value.
258
+ *
259
+ * @param defaultValue - Value to return if the Option is none
260
+ * @returns A function that takes an Option and returns the value or default
261
+ *
262
+ * @example
263
+ * ```ts
264
+ * pipe(some(42), unwrapOr(0)) // 42
265
+ * pipe(none(), unwrapOr(0)) // 0
266
+ * ```
267
+ */
268
+ const unwrapOr = (defaultValue) => (option) => option.some ? option.value : defaultValue;
269
+ /**
270
+ * Get the value or compute a value.
271
+ *
272
+ * @param fn - Function to compute a value
273
+ * @returns A function that takes an Option and returns the value or computed value
274
+ *
275
+ * @example
276
+ * ```ts
277
+ * pipe(
278
+ * none(),
279
+ * unwrapOrElse(() => generateDefault())
280
+ * ) // generateDefault()
281
+ * ```
282
+ */
283
+ const unwrapOrElse = (fn) => (option) => option.some ? option.value : fn();
284
+ /**
285
+ * Pattern match on an Option, handling both some and none cases.
286
+ *
287
+ * @param handlers - Object with some and none handlers
288
+ * @returns A function that takes an Option and returns the handler result
289
+ *
290
+ * @example
291
+ * ```ts
292
+ * pipe(
293
+ * some(42),
294
+ * match({
295
+ * some: n => `Got ${n}`,
296
+ * none: () => 'No value'
297
+ * })
298
+ * ) // 'Got 42'
299
+ * ```
300
+ */
301
+ const match = (handlers) => (option) => option.some ? handlers.some(option.value) : handlers.none();
302
+ /**
303
+ * Convert a nullable value to an Option.
304
+ * null and undefined become none, other values become some.
305
+ *
306
+ * @param value - The value to convert
307
+ * @returns An Option
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * fromNullable(42) // { some: true, value: 42 }
312
+ * fromNullable(null) // { some: false }
313
+ * fromNullable(undefined) // { some: false }
314
+ * ```
315
+ */
316
+ const fromNullable = (value) => value === null || value === void 0 ? none() : some(value);
317
+ /**
318
+ * Wrap a function that might throw into an Option.
319
+ * Supports both sync and async functions with automatic type inference.
320
+ *
321
+ * - Sync fn: returns Option<T>
322
+ * - Async fn: returns Promise<Option<T>>
323
+ *
324
+ * **Note on `any` return types:** If your function returns `any` (e.g., `JSON.parse`),
325
+ * you should add an explicit return type annotation. This is because TypeScript's
326
+ * conditional types cannot determine if `any` is a Promise or not, resulting in a
327
+ * union type `Promise<Option<unknown>> | Option<any>` that won't work
328
+ * with Option utilities like `isSome` or `isNone`.
329
+ *
330
+ * @param fn - Function that might throw (sync or async)
331
+ * @returns An Option with the return value or none
332
+ *
333
+ * @example
334
+ * ```ts
335
+ * // Sync usage
336
+ * fromTry(() => JSON.parse('{"valid": true}'))
337
+ * // { some: true, value: { valid: true } }
338
+ *
339
+ * fromTry(() => JSON.parse('not json'))
340
+ * // { some: false }
341
+ *
342
+ * // When fn returns `any`, add explicit return type:
343
+ * fromTry((): unknown => JSON.parse(input))
344
+ * fromTry((): MyType => JSON.parse(input))
345
+ *
346
+ * // Async usage
347
+ * await fromTry(async () => await fetch('/api/user'))
348
+ * // Promise<Option<Response>>
349
+ *
350
+ * await fromTry(async () => {
351
+ * throw new Error('network error')
352
+ * })
353
+ * // Promise<{ some: false }>
354
+ * ```
355
+ */
356
+ const fromTry = (fn) => {
357
+ try {
358
+ const result = fn();
359
+ if (isPromise(result)) return result.then(some).catch(() => none());
360
+ return some(result);
361
+ } catch {
362
+ return none();
363
+ }
364
+ };
365
+ /**
366
+ * Option namespace containing all utility functions for working with Option types.
367
+ *
368
+ * Option represents either the presence (some) or absence (none) of a value.
369
+ * Use this for optional values without needing to track why the value is missing.
370
+ *
371
+ * @see {@link Result} for success/failure with error information
372
+ * @see {@link Either} for two valid outcomes
373
+ *
374
+ * @example
375
+ * ```ts
376
+ * import { Option, pipe } from '@repo/std'
377
+ * import type { Option as OptionType } from '@repo/std'
378
+ *
379
+ * const findUser = (id: number): OptionType<User> =>
380
+ * id > 0 ? Option.some({ id, name: 'Alice' }) : Option.none()
381
+ *
382
+ * const result = pipe(
383
+ * Option.some(10),
384
+ * Option.flatMap(findUser),
385
+ * Option.map(user => user.name),
386
+ * Option.unwrapOr('Unknown')
387
+ * )
388
+ * ```
389
+ */
390
+ const Option = {
391
+ some,
392
+ none,
393
+ isSome,
394
+ isNone,
395
+ map,
396
+ flatMap,
397
+ tap,
398
+ orElse,
399
+ filter,
400
+ all,
401
+ unwrapOr,
402
+ unwrapOrElse,
403
+ match,
404
+ fromNullable,
405
+ fromTry
406
+ };
407
+
408
+ //#endregion
409
+ export { None as n, Option as t };
410
+ //# sourceMappingURL=option-CKHDOVea.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option-CKHDOVea.mjs","names":["NoneValue","values"],"sources":["../src/option/option.types.ts","../src/option/option.ts"],"sourcesContent":["import type { Yieldable } from \"../gen/gen.types\"\n\n// ============================================================================\n// None Type\n// ============================================================================\n\n/**\n * Marker type for Option's absence in the Do computation context.\n * When an Option is yielded in Do, None becomes part of the error union.\n */\nexport type None = { readonly __typename: \"None\" }\n\n/**\n * Singleton None value.\n */\nexport const None: None = { __typename: \"None\" }\n\n// ============================================================================\n// Option Type\n// ============================================================================\n\n/**\n * A discriminated union representing either a value (some) or absence (none).\n * Compatible with ts-pattern for exhaustive matching.\n * Implements Yieldable protocol for use in Do computations with yield*.\n */\nexport type Option<T> = Yieldable<T, None> & ({ readonly some: true; readonly value: T } | { readonly some: false })\n\n// ============================================================================\n// Async-aware transformation types\n// ============================================================================\n\n/**\n * Compute the return type of `map` based on whether fn returns a Promise.\n * - If fn returns Promise<U>, result is Promise<Option<U>>\n * - If fn returns U, result is Option<U>\n */\nexport type MapReturn<FnReturn> = FnReturn extends Promise<infer U> ? Promise<Option<U>> : Option<FnReturn>\n\n/**\n * Compute the return type of `flatMap` based on whether fn returns a Promise.\n * - If fn returns Promise<Option<U>>, result is Promise<Option<U>>\n * - If fn returns Option<U>, result is Option<U>\n */\nexport type FlatMapReturn<FnReturn> =\n FnReturn extends Promise<Option<infer U>> ? Promise<Option<U>> : FnReturn extends Option<infer U> ? Option<U> : never\n\n/**\n * Compute the return type of `tap` based on whether fn returns a Promise.\n * - If fn returns Promise<any>, result is Promise<Option<T>>\n * - If fn returns any, result is Option<T>\n * The result value is always unchanged.\n */\n// oxlint-disable-next-line no-explicit-any\nexport type TapReturn<FnReturn, T> = FnReturn extends Promise<any> ? Promise<Option<T>> : Option<T>\n\n/**\n * Compute the return type of `orElse` based on whether fn returns a Promise.\n * - If fn returns Promise<Option<U>>, result is Promise<Option<T | U>>\n * - If fn returns Option<U>, result is Option<T | U>\n */\nexport type OrElseReturn<FnReturn, T> =\n FnReturn extends Promise<Option<infer U>>\n ? Promise<Option<T | U>>\n : FnReturn extends Option<infer U>\n ? Option<T | U>\n : never\n\n/**\n * Compute the return type of `fromTry` based on whether fn returns a Promise.\n * - If fn returns Promise<T>, result is Promise<Option<T>>\n * - If fn returns T, result is Option<T>\n */\nexport type FromTryReturn<T> = T extends Promise<infer U> ? Promise<Option<U>> : Option<T>\n\n// ============================================================================\n// All/Combine types\n// ============================================================================\n\n/**\n * Extract the value type from an Option.\n * Uses structural matching to extract the value type from the some branch.\n */\nexport type OptionValue<O> = O extends { readonly some: true; readonly value: infer T } ? T : never\n\n/**\n * Compute return type for `all` with array input.\n * Preserves tuple structure and extracts value types from each position.\n */\nexport type AllArrayReturn<T extends readonly Option<unknown>[]> = Option<{\n -readonly [K in keyof T]: OptionValue<T[K]>\n}>\n\n/**\n * Compute return type for `all` with object input.\n * Preserves object structure and extracts value types from each key.\n */\nexport type AllObjectReturn<T extends Record<string, Option<unknown>>> = Option<{\n -readonly [K in keyof T]: OptionValue<T[K]>\n}>\n\n// ============================================================================\n// Function Interfaces for improved pipe inference\n// ============================================================================\n\n/**\n * Interface for flatMap - using method syntax improves generic inference in pipe chains.\n * Note: Async overload must come first for proper overload resolution.\n */\nexport type OptionFlatMap = {\n <A, B>(fn: (value: A) => Promise<Option<B>>): (option: Option<A>) => Promise<Option<B>>\n <A, B>(fn: (value: A) => Option<B>): (option: Option<A>) => Option<B>\n}\n\n/**\n * Interface for map function.\n * Note: Async overload must come first for proper overload resolution.\n */\nexport type OptionMap = {\n <A, B>(fn: (value: A) => Promise<B>): (option: Option<A>) => Promise<Option<B>>\n <A, B>(fn: (value: A) => B): (option: Option<A>) => Option<B>\n}\n\n/**\n * Interface for tap function.\n */\nexport type OptionTap = {\n <A, R>(fn: (value: A) => R): (option: Option<A>) => R extends Promise<unknown> ? Promise<Option<A>> : Option<A>\n}\n\n/**\n * Interface for orElse function.\n * Note: Async overload must come first for proper overload resolution.\n */\nexport type OptionOrElse = {\n <A, B>(fn: () => Promise<Option<B>>): (option: Option<A>) => Promise<Option<A | B>>\n <A, B>(fn: () => Option<B>): (option: Option<A>) => Option<A | B>\n}\n\n/**\n * Interface for filter function.\n */\nexport type OptionFilter = {\n <A>(predicate: (value: A) => boolean): (option: Option<A>) => Option<A>\n}\n","import { isPromise } from \"../shared/is-promise\"\nimport { None as NoneValue } from \"./option.types\"\nimport type {\n AllArrayReturn,\n AllObjectReturn,\n Option as OptionType,\n OptionFlatMap,\n OptionMap,\n OptionTap,\n OptionOrElse,\n OptionFilter,\n None,\n FromTryReturn,\n} from \"./option.types\"\n\n// ============================================================================\n// Constructors\n// ============================================================================\n\n/**\n * Create an Option with a value.\n *\n * @param value - The value to wrap\n * @returns An Option with some: true\n *\n * @example\n * ```ts\n * some(42) // { some: true, value: 42 }\n * ```\n */\nexport const some = <T>(value: T): OptionType<T> => ({\n some: true,\n value,\n // oxlint-disable-next-line require-yield\n *[Symbol.iterator](): Generator<None, T, unknown> {\n return value\n },\n})\n\n/**\n * Create an Option with no value.\n *\n * @returns An Option with some: false\n *\n * @example\n * ```ts\n * none() // { some: false }\n * ```\n */\nexport const none = <T>(): OptionType<T> => ({\n some: false,\n *[Symbol.iterator](): Generator<None, never, unknown> {\n yield NoneValue\n throw new Error(\"Unreachable: Do should short-circuit on None\")\n },\n})\n\n// ============================================================================\n// Type Guards\n// ============================================================================\n\n/**\n * Check if an Option has a value.\n *\n * @param option - The Option to check\n * @returns true if the Option is some\n *\n * @example\n * ```ts\n * const option = some(42)\n * if (isSome(option)) {\n * console.log(option.value) // TypeScript knows value exists\n * }\n * ```\n */\nexport const isSome = <T>(option: OptionType<T>): option is Extract<OptionType<T>, { some: true }> => option.some\n\n/**\n * Check if an Option has no value.\n *\n * @param option - The Option to check\n * @returns true if the Option is none\n *\n * @example\n * ```ts\n * const option = none()\n * if (isNone(option)) {\n * console.log('No value') // TypeScript knows value doesn't exist\n * }\n * ```\n */\nexport const isNone = <T>(option: OptionType<T>): option is Extract<OptionType<T>, { some: false }> => !option.some\n\n// ============================================================================\n// Transformations (curried for pipe)\n// ============================================================================\n\n/**\n * Transform the value of an Option.\n * If the Option is none, it passes through unchanged.\n *\n * Supports both sync and async functions:\n * - Sync fn: returns Option<U>\n * - Async fn: returns Promise<Option<U>>\n *\n * @param fn - Function to transform the value\n * @returns A function that takes an Option and returns a new Option\n *\n * @example\n * ```ts\n * // Sync usage\n * pipe(\n * some(5),\n * map(n => n * 2)\n * ) // { some: true, value: 10 }\n *\n * // Async usage\n * await pipe(\n * some(userId),\n * map(async id => await fetchName(id))\n * ) // Promise<Option<string>>\n * ```\n */\n/* oxlint-disable no-explicit-any, no-unsafe-return, no-unsafe-type-assertion -- Required for overloaded return types in curried functions */\nexport const map: OptionMap = (fn) => (option) => {\n if (!option.some) return option as any\n const mapped = fn(option.value)\n if (mapped instanceof Promise) {\n return mapped.then(some) as any\n }\n return some(mapped) as any\n}\n/* oxlint-enable no-explicit-any, no-unsafe-return, no-unsafe-type-assertion */\n\n/**\n * Chain operations that return Options.\n * If the Option is none, it passes through unchanged.\n *\n * Supports both sync and async functions:\n * - Sync fn: returns Option<U>\n * - Async fn: returns Promise<Option<U>>\n *\n * @param fn - Function that takes a value and returns an Option (or Promise<Option>)\n * @returns A function that takes an Option and returns a new Option\n *\n * @example\n * ```ts\n * const findUser = (id: number) =>\n * id > 0 ? some({ id, name: 'Alice' }) : none()\n *\n * // Sync usage\n * pipe(\n * some(10),\n * flatMap(id => findUser(id))\n * ) // { some: true, value: { id: 10, name: 'Alice' } }\n *\n * // Async usage\n * await pipe(\n * some(userId),\n * flatMap(async id => some(await fetchUser(id)))\n * ) // Promise<Option<User>>\n * ```\n */\n// oxlint-disable-next-line no-explicit-any, no-unsafe-return, no-unsafe-type-assertion -- Required for overloaded return types\nexport const flatMap: OptionFlatMap = (fn) => (option) => (option.some ? fn(option.value) : option) as any\n\n/**\n * Perform a side effect on the value without modifying the Option.\n * Useful for debugging, logging, or other side effects in a pipeline.\n * If the Option is none, the function is not called.\n *\n * Supports both sync and async functions:\n * - Sync fn: returns Option<T>\n * - Async fn: returns Promise<Option<T>>\n *\n * @param fn - Function to call with the value (return value is ignored)\n * @returns A function that takes an Option and returns the same Option\n *\n * @example\n * ```ts\n * // Sync usage\n * pipe(\n * some(42),\n * tap(console.log), // logs 42\n * map(n => n * 2)\n * ) // { some: true, value: 84 }\n *\n * // Async usage\n * await pipe(\n * some(42),\n * tap(async v => await logToServer(v)),\n * map(n => n * 2)\n * ) // Promise<Option<84>>\n * ```\n */\n/* oxlint-disable no-explicit-any, no-unsafe-return, no-unsafe-type-assertion -- Required for overloaded return types in curried functions */\nexport const tap: OptionTap = (fn) => (option) => {\n if (!option.some) return option as any\n const sideEffect = fn(option.value)\n if (sideEffect instanceof Promise) {\n return sideEffect.then(() => option) as any\n }\n return option as any\n}\n/* oxlint-enable no-explicit-any, no-unsafe-return, no-unsafe-type-assertion */\n\n/**\n * Recover from none by providing an alternative Option.\n * If the Option is some, it passes through unchanged.\n *\n * Supports both sync and async functions:\n * - Sync fn: returns Option<T | U>\n * - Async fn: returns Promise<Option<T | U>>\n *\n * @param fn - Function that returns an alternative Option\n * @returns A function that takes an Option and returns a new Option\n *\n * @example\n * ```ts\n * // Sync recovery\n * pipe(\n * none(),\n * orElse(() => some(defaultValue))\n * ) // { some: true, value: defaultValue }\n *\n * // Async recovery\n * await pipe(\n * none(),\n * orElse(async () => some(await fetchFromAPI()))\n * ) // Promise<Option<T>>\n *\n * // Chain multiple fallbacks\n * pipe(\n * none(),\n * orElse(() => tryCache()),\n * orElse(() => tryAPI()),\n * orElse(() => some(fallback))\n * )\n * ```\n */\n// oxlint-disable-next-line no-explicit-any, no-unsafe-return, no-unsafe-type-assertion -- Required for overloaded return types\nexport const orElse: OptionOrElse = (fn) => (option) => (option.some ? option : fn()) as any\n\n/**\n * Filter an Option based on a predicate.\n * If the predicate returns false, converts to none.\n * If the Option is already none, it passes through unchanged.\n *\n * @param predicate - Function that returns true to keep the value\n * @returns A function that takes an Option and returns a new Option\n *\n * @example\n * ```ts\n * pipe(\n * some(5),\n * filter(n => n > 10)\n * ) // { some: false }\n *\n * pipe(\n * some(15),\n * filter(n => n > 10)\n * ) // { some: true, value: 15 }\n *\n * // With complex validation\n * pipe(\n * some(user),\n * filter(u => u.age >= 18)\n * )\n * ```\n */\nexport const filter: OptionFilter = (predicate) => (option) => {\n if (!option.some) return option\n return predicate(option.value) ? option : none()\n}\n\n// ============================================================================\n// Combinators\n// ============================================================================\n\n/**\n * Combine multiple Options into a single Option.\n * Supports both array and object inputs.\n *\n * - If all Options are some, returns some with all values\n * - If any Option is none, returns none (short-circuits)\n *\n * @example\n * ```ts\n * // Array form (use `as const` for tuple types) - returns Option<[number, string]>\n * const [num, str] = pipe(\n * Option.all([parseNumber(input), parseString(other)] as const),\n * Option.unwrapOr([0, ''])\n * )\n *\n * // Object form - returns Option<{ user: User, config: Config }>\n * pipe(\n * Option.all({ user: findUser(id), config: loadConfig() }),\n * Option.tap(({ user, config }) => console.log(user.name, config.theme))\n * )\n * ```\n */\nexport function all<T extends readonly OptionType<unknown>[]>(options: T): AllArrayReturn<T>\nexport function all<T extends Record<string, OptionType<unknown>>>(options: T): AllObjectReturn<T>\n/* oxlint-disable no-explicit-any, no-unsafe-return, no-unsafe-member-access, strict-boolean-expressions, no-unsafe-type-assertion, no-unsafe-argument -- Required for handling union types in overloaded function */\nexport function all(options: any): any {\n if (Array.isArray(options)) {\n const values: unknown[] = []\n for (const option of options) {\n if (!option.some) return option\n values.push(option.value)\n }\n return some(values)\n }\n\n const values: Record<string, unknown> = {}\n for (const [key, option] of Object.entries(options)) {\n const o = option as OptionType<unknown>\n if (!o.some) return option\n values[key] = o.value\n }\n return some(values)\n}\n/* oxlint-enable no-explicit-any, no-unsafe-return, no-unsafe-member-access, strict-boolean-expressions, no-unsafe-type-assertion */\n\n// ============================================================================\n// Extraction\n// ============================================================================\n\n/**\n * Get the value or a default value.\n *\n * @param defaultValue - Value to return if the Option is none\n * @returns A function that takes an Option and returns the value or default\n *\n * @example\n * ```ts\n * pipe(some(42), unwrapOr(0)) // 42\n * pipe(none(), unwrapOr(0)) // 0\n * ```\n */\nexport const unwrapOr =\n <T>(defaultValue: T) =>\n (option: OptionType<T>): T =>\n option.some ? option.value : defaultValue\n\n/**\n * Get the value or compute a value.\n *\n * @param fn - Function to compute a value\n * @returns A function that takes an Option and returns the value or computed value\n *\n * @example\n * ```ts\n * pipe(\n * none(),\n * unwrapOrElse(() => generateDefault())\n * ) // generateDefault()\n * ```\n */\nexport const unwrapOrElse =\n <T>(fn: () => T) =>\n (option: OptionType<T>): T =>\n option.some ? option.value : fn()\n\n/**\n * Pattern match on an Option, handling both some and none cases.\n *\n * @param handlers - Object with some and none handlers\n * @returns A function that takes an Option and returns the handler result\n *\n * @example\n * ```ts\n * pipe(\n * some(42),\n * match({\n * some: n => `Got ${n}`,\n * none: () => 'No value'\n * })\n * ) // 'Got 42'\n * ```\n */\nexport const match =\n <T, U>(handlers: { some: (value: T) => U; none: () => U }) =>\n (option: OptionType<T>): U =>\n option.some ? handlers.some(option.value) : handlers.none()\n\n// ============================================================================\n// Conversions\n// ============================================================================\n\n/**\n * Convert a nullable value to an Option.\n * null and undefined become none, other values become some.\n *\n * @param value - The value to convert\n * @returns An Option\n *\n * @example\n * ```ts\n * fromNullable(42) // { some: true, value: 42 }\n * fromNullable(null) // { some: false }\n * fromNullable(undefined) // { some: false }\n * ```\n */\nexport const fromNullable = <T>(value: T | null | undefined): OptionType<T> =>\n value === null || value === undefined ? none<T>() : some(value)\n\n/**\n * Wrap a function that might throw into an Option.\n * Supports both sync and async functions with automatic type inference.\n *\n * - Sync fn: returns Option<T>\n * - Async fn: returns Promise<Option<T>>\n *\n * **Note on `any` return types:** If your function returns `any` (e.g., `JSON.parse`),\n * you should add an explicit return type annotation. This is because TypeScript's\n * conditional types cannot determine if `any` is a Promise or not, resulting in a\n * union type `Promise<Option<unknown>> | Option<any>` that won't work\n * with Option utilities like `isSome` or `isNone`.\n *\n * @param fn - Function that might throw (sync or async)\n * @returns An Option with the return value or none\n *\n * @example\n * ```ts\n * // Sync usage\n * fromTry(() => JSON.parse('{\"valid\": true}'))\n * // { some: true, value: { valid: true } }\n *\n * fromTry(() => JSON.parse('not json'))\n * // { some: false }\n *\n * // When fn returns `any`, add explicit return type:\n * fromTry((): unknown => JSON.parse(input))\n * fromTry((): MyType => JSON.parse(input))\n *\n * // Async usage\n * await fromTry(async () => await fetch('/api/user'))\n * // Promise<Option<Response>>\n *\n * await fromTry(async () => {\n * throw new Error('network error')\n * })\n * // Promise<{ some: false }>\n * ```\n */\n/* oxlint-disable no-explicit-any, no-unsafe-type-assertion -- Required for conditional return type */\nexport const fromTry = <T>(fn: () => T): FromTryReturn<T> => {\n try {\n const result = fn()\n if (isPromise(result)) {\n return result.then(some).catch(() => none()) as unknown as FromTryReturn<T>\n }\n return some(result) as unknown as FromTryReturn<T>\n } catch {\n return none() as unknown as FromTryReturn<T>\n }\n}\n\n// ============================================================================\n// Namespace\n// ============================================================================\n\n/**\n * Option namespace containing all utility functions for working with Option types.\n *\n * Option represents either the presence (some) or absence (none) of a value.\n * Use this for optional values without needing to track why the value is missing.\n *\n * @see {@link Result} for success/failure with error information\n * @see {@link Either} for two valid outcomes\n *\n * @example\n * ```ts\n * import { Option, pipe } from '@repo/std'\n * import type { Option as OptionType } from '@repo/std'\n *\n * const findUser = (id: number): OptionType<User> =>\n * id > 0 ? Option.some({ id, name: 'Alice' }) : Option.none()\n *\n * const result = pipe(\n * Option.some(10),\n * Option.flatMap(findUser),\n * Option.map(user => user.name),\n * Option.unwrapOr('Unknown')\n * )\n * ```\n */\nexport const Option = {\n some,\n none,\n isSome,\n isNone,\n map,\n flatMap,\n tap,\n orElse,\n filter,\n all,\n unwrapOr,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mB;AACrC,KAAI,MAAM,QAAQ,QAAQ,EAAE;EAC1B,MAAMC,WAAoB,EAAE;AAC5B,OAAK,MAAM,UAAU,SAAS;AAC5B,OAAI,CAAC,OAAO,KAAM,QAAO;AACzB,YAAO,KAAK,OAAO,MAAM;;AAE3B,SAAO,KAAKA,SAAO;;CAGrB,MAAM,SAAkC,EAAE;AAC1C,MAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,QAAQ,EAAE;EACnD,MAAM,IAAI;AACV,MAAI,CAAC,EAAE,KAAM,QAAO;AACpB,SAAO,OAAO,EAAE;;AAElB,QAAO,KAAK,OAAO;;;;;;;;;;;;;;AAoBrB,MAAa,YACP,kBACH,WACC,OAAO,OAAO,OAAO,QAAQ;;;;;;;;;;;;;;;AAgBjC,MAAa,gBACP,QACH,WACC,OAAO,OAAO,OAAO,QAAQ,IAAI;;;;;;;;;;;;;;;;;;AAmBrC,MAAa,SACJ,cACN,WACC,OAAO,OAAO,SAAS,KAAK,OAAO,MAAM,GAAG,SAAS,MAAM;;;;;;;;;;;;;;;AAoB/D,MAAa,gBAAmB,UAC9B,UAAU,QAAQ,UAAU,SAAY,MAAS,GAAG,KAAK,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CjE,MAAa,WAAc,OAAkC;AAC3D,KAAI;EACF,MAAM,SAAS,IAAI;AACnB,MAAI,UAAU,OAAO,CACnB,QAAO,OAAO,KAAK,KAAK,CAAC,YAAY,MAAM,CAAC;AAE9C,SAAO,KAAK,OAAO;SACb;AACN,SAAO,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCjB,MAAa,SAAS;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
@@ -0,0 +1,89 @@
1
+ import { g as Yieldable } from "./result.types-Ce7AEOzj.mjs";
2
+
3
+ //#region src/option/option.types.d.ts
4
+
5
+ /**
6
+ * Marker type for Option's absence in the Do computation context.
7
+ * When an Option is yielded in Do, None becomes part of the error union.
8
+ */
9
+ type None = {
10
+ readonly __typename: "None";
11
+ };
12
+ /**
13
+ * Singleton None value.
14
+ */
15
+ declare const None: None;
16
+ /**
17
+ * A discriminated union representing either a value (some) or absence (none).
18
+ * Compatible with ts-pattern for exhaustive matching.
19
+ * Implements Yieldable protocol for use in Do computations with yield*.
20
+ */
21
+ type Option<T> = Yieldable<T, None> & ({
22
+ readonly some: true;
23
+ readonly value: T;
24
+ } | {
25
+ readonly some: false;
26
+ });
27
+ /**
28
+ * Compute the return type of `fromTry` based on whether fn returns a Promise.
29
+ * - If fn returns Promise<T>, result is Promise<Option<T>>
30
+ * - If fn returns T, result is Option<T>
31
+ */
32
+ type FromTryReturn<T> = T extends Promise<infer U> ? Promise<Option<U>> : Option<T>;
33
+ /**
34
+ * Extract the value type from an Option.
35
+ * Uses structural matching to extract the value type from the some branch.
36
+ */
37
+ type OptionValue<O> = O extends {
38
+ readonly some: true;
39
+ readonly value: infer T;
40
+ } ? T : never;
41
+ /**
42
+ * Compute return type for `all` with array input.
43
+ * Preserves tuple structure and extracts value types from each position.
44
+ */
45
+ type AllArrayReturn<T extends readonly Option<unknown>[]> = Option<{ -readonly [K in keyof T]: OptionValue<T[K]> }>;
46
+ /**
47
+ * Compute return type for `all` with object input.
48
+ * Preserves object structure and extracts value types from each key.
49
+ */
50
+ type AllObjectReturn<T extends Record<string, Option<unknown>>> = Option<{ -readonly [K in keyof T]: OptionValue<T[K]> }>;
51
+ /**
52
+ * Interface for flatMap - using method syntax improves generic inference in pipe chains.
53
+ * Note: Async overload must come first for proper overload resolution.
54
+ */
55
+ type OptionFlatMap = {
56
+ <A, B>(fn: (value: A) => Promise<Option<B>>): (option: Option<A>) => Promise<Option<B>>;
57
+ <A, B>(fn: (value: A) => Option<B>): (option: Option<A>) => Option<B>;
58
+ };
59
+ /**
60
+ * Interface for map function.
61
+ * Note: Async overload must come first for proper overload resolution.
62
+ */
63
+ type OptionMap = {
64
+ <A, B>(fn: (value: A) => Promise<B>): (option: Option<A>) => Promise<Option<B>>;
65
+ <A, B>(fn: (value: A) => B): (option: Option<A>) => Option<B>;
66
+ };
67
+ /**
68
+ * Interface for tap function.
69
+ */
70
+ type OptionTap = {
71
+ <A, R>(fn: (value: A) => R): (option: Option<A>) => R extends Promise<unknown> ? Promise<Option<A>> : Option<A>;
72
+ };
73
+ /**
74
+ * Interface for orElse function.
75
+ * Note: Async overload must come first for proper overload resolution.
76
+ */
77
+ type OptionOrElse = {
78
+ <A, B>(fn: () => Promise<Option<B>>): (option: Option<A>) => Promise<Option<A | B>>;
79
+ <A, B>(fn: () => Option<B>): (option: Option<A>) => Option<A | B>;
80
+ };
81
+ /**
82
+ * Interface for filter function.
83
+ */
84
+ type OptionFilter = {
85
+ <A>(predicate: (value: A) => boolean): (option: Option<A>) => Option<A>;
86
+ };
87
+ //#endregion
88
+ export { Option as a, OptionMap as c, None as i, OptionOrElse as l, AllObjectReturn as n, OptionFilter as o, FromTryReturn as r, OptionFlatMap as s, AllArrayReturn as t, OptionTap as u };
89
+ //# sourceMappingURL=option.types-D6TYG_i3.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option.types-D6TYG_i3.d.mts","names":[],"sources":["../src/option/option.types.ts"],"sourcesContent":[],"mappings":";;;;;;AAUA;AAKA;AAWY,KAhBA,IAAA,GAgBM;EAAgB,SAAA,UAAA,EAAA,MAAA;CAAG;;;;AA+CzB,cA1DC,IA0DY,EA1DN,IA0DM;;;;;;AAA+D,KA/C5E,MA+C4E,CAAA,CAAA,CAAA,GA/ChE,SA+CgE,CA/CtD,CA+CsD,EA/CnD,IA+CmD,CAAA,GAAA,CAAA;EAAP,SAAA,IAAA,EAAA,IAAA;EAAM,SAAA,KAAA,EA/CF,CA+CE;AAUvF,CAAA,GAAY;EAMA,SAAA,IAAA,EAAA,KAAc;CAAoB,CAAA;;;;;;AAsBuB,KAtCzD,aAsCyD,CAAA,CAAA,CAAA,GAt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CAOD,CAAA,CAAA,EAAA,CAAA,MAAA,EAPe,MAOf,CAPsB,CAOtB,CAAA,EAAA,GAP6B,MAO7B,CAPoC,CAOpC,GAPwC,CAOxC,CAAA;CAAgC;;;;AAAa,KAD1D,YAAA,GAC0D;yBAA7C,yBAAyB,OAAO,OAAO,OAAO"}
@@ -0,0 +1,2 @@
1
+ import { t as pipe } from "../index-yyBTq8Ys.mjs";
2
+ export { pipe };
@@ -0,0 +1,3 @@
1
+ import { t as pipe } from "../pipe-GYxZNkPB.mjs";
2
+
3
+ export { pipe };
@@ -0,0 +1,10 @@
1
+ import { t as flow } from "./flow-pRdnqmMY.mjs";
2
+
3
+ //#region src/pipe/pipe.ts
4
+ function pipe(arg, ...fns) {
5
+ return flow(...fns)(arg);
6
+ }
7
+
8
+ //#endregion
9
+ export { pipe as t };
10
+ //# sourceMappingURL=pipe-GYxZNkPB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipe-GYxZNkPB.mjs","names":[],"sources":["../src/pipe/pipe.ts"],"sourcesContent":["import { flow } from \"../flow/flow\"\nimport type { PipeReturn } from \"../pipe/pipe.types\"\nimport type { λ } from \"../shared/lambda.types\"\n\n/**\n * Like `flow` but takes an argument as its first parameter and invokes the pipe\n * with it.\n *\n * Note: unlike in `flow`, the first function of the pipe must take exactly one\n * argument.\n *\n * Type inference: This function provides automatic type inference for chains of\n * 1-15 functions. Each function's parameter type is automatically inferred from\n * the previous function's return type. For chains longer than 15 functions,\n * types must be explicitly specified.\n *\n * Async support: Functions can return Promises. The runtime automatically awaits\n * Promises before passing values to subsequent functions, and parameter types\n * use `Awaited<T>` to reflect this behavior. The final return type will be\n * Promise<T> if any function returns a Promise.\n *\n * @see {@link flow} for point-free function composition (returns a function)\n *\n * @example\n * ```typescript\n * // Type inference in action\n * pipe(\n * 2,\n * (n) => n * 2, // n: number (inferred from initial value)\n * (n) => n + 1, // n: number (inferred from previous return)\n * (n) => n.toString() // n: number (inferred from previous return)\n * ) // -> \"5\"\n *\n * // With type transformations\n * pipe(\n * 5,\n * (n) => n.toString(), // number -> string\n * (s) => s.length, // string -> number (inferred!)\n * (n) => n * 2 // number -> number (inferred!)\n * )\n *\n * // With async functions - Promises are automatically unwrapped\n * await pipe(\n * 5,\n * async (n) => n * 2, // number -> Promise<number>\n * (n) => n.toString(), // n: number (Promise unwrapped!)\n * async (s) => s.length // string -> Promise<number>\n * )\n * ```\n */\n// 1 function\nexport function pipe<A, B>(arg: A, f1: (arg: A) => B): PipeReturn<[typeof f1], A>\n// 2 functions\nexport function pipe<A, B, C>(\n arg: A,\n f1: (arg: A) => B,\n f2: (arg: Awaited<B>) => C,\n): PipeReturn<[typeof f1, typeof f2], A>\n// 3 functions\nexport function pipe<A, B, C, D>(\n arg: A,\n f1: (arg: A) => B,\n f2: (arg: Awaited<B>) => C,\n f3: (arg: Awaited<C>) => D,\n): PipeReturn<[typeof f1, typeof f2, typeof f3], A>\n// 4 functions\nexport function pipe<A, B, C, D, E>(\n arg: A,\n f1: (arg: A) => B,\n f2: (arg: Awaited<B>) => C,\n f3: (arg: Awaited<C>) => D,\n f4: (arg: Awaited<D>) => E,\n): PipeReturn<[typeof f1, typeof f2, typeof f3, typeof f4], A>\n// 5 functions\nexport function pipe<A, B, C, D, E, F>(\n arg: A,\n f1: (arg: A) => B,\n f2: (arg: Awaited<B>) => C,\n f3: (arg: Awaited<C>) => D,\n f4: (arg: Awaited<D>) => E,\n f5: (arg: Awaited<E>) => F,\n): PipeReturn<[typeof f1, typeof f2, typeof f3, typeof f4, typeof f5], A>\n// 6 functions\nexport function pipe<A, B, C, D, E, F, G>(\n arg: A,\n f1: (arg: A) => B,\n f2: (arg: Awaited<B>) => C,\n f3: (arg: Awaited<C>) => D,\n f4: (arg: Awaited<D>) => E,\n f5: (arg: Awaited<E>) => F,\n f6: (arg: Awaited<F>) => G,\n): PipeReturn<[typeof f1, typeof f2, typeof f3, typeof f4, typeof f5, typeof f6], A>\n// 7 functions\nexport function pipe<A, B, C, D, E, F, G, H>(\n arg: A,\n f1: (arg: A) => B,\n f2: (arg: Awaited<B>) => C,\n f3: (arg: Awaited<C>) => D,\n f4: (arg: Awaited<D>) => E,\n f5: (arg: Awaited<E>) => F,\n f6: (arg: Awaited<F>) => G,\n f7: (arg: Awaited<G>) => H,\n): PipeReturn<[typeof f1, typeof f2, typeof f3, typeof f4, typeof f5, typeof f6, typeof f7], A>\n// 8 functions\nexport function pipe<A, B, C, D, E, F, G, H, I>(\n arg: A,\n f1: (arg: A) => B,\n f2: (arg: Awaited<B>) => C,\n f3: (arg: Awaited<C>) => D,\n f4: (arg: Awaited<D>) => E,\n f5: (arg: Awaited<E>) => F,\n f6: (arg: Awaited<F>) => G,\n f7: (arg: Awaited<G>) => H,\n f8: (arg: Awaited<H>) => I,\n): PipeReturn<[typeof f1, typeof f2, typeof f3, typeof f4, typeof f5, typeof f6, typeof f7, typeof f8], A>\n// 9 functions\nexport function pipe<A, B, C, D, E, F, G, H, I, J>(\n arg: A,\n f1: (arg: A) => B,\n f2: (arg: Awaited<B>) => C,\n f3: (arg: Awaited<C>) => D,\n f4: (arg: Awaited<D>) => E,\n f5: (arg: Awaited<E>) => F,\n f6: (arg: Awaited<F>) => G,\n f7: (arg: Awaited<G>) => H,\n f8: (arg: Awaited<H>) => I,\n f9: (arg: Awaited<I>) => J,\n): PipeReturn<[typeof f1, typeof f2, typeof f3, typeof f4, typeof f5, typeof f6, typeof f7, typeof f8, typeof f9], A>\n// 10 functions\nexport function pipe<A, B, C, D, E, F, G, H, I, J, K>(\n arg: A,\n f1: (arg: A) => B,\n f2: (arg: Awaited<B>) => C,\n f3: (arg: Awaited<C>) => D,\n f4: (arg: Awaited<D>) => E,\n f5: (arg: Awaited<E>) => F,\n f6: (arg: Awaited<F>) => G,\n f7: (arg: Awaited<G>) => H,\n f8: (arg: Awaited<H>) => I,\n f9: (arg: Awaited<I>) => J,\n f10: (arg: Awaited<J>) => K,\n): PipeReturn<\n [typeof f1, typeof f2, typeof f3, typeof f4, typeof f5, typeof f6, typeof f7, typeof f8, typeof f9, typeof f10],\n A\n>\n// 11 functions\nexport function pipe<A, B, C, D, E, F, G, H, I, J, K, L>(\n arg: A,\n f1: (arg: A) => B,\n f2: (arg: Awaited<B>) => C,\n f3: (arg: Awaited<C>) => D,\n f4: (arg: Awaited<D>) => E,\n f5: (arg: Awaited<E>) => F,\n f6: (arg: Awaited<F>) => G,\n f7: (arg: Awaited<G>) => H,\n f8: (arg: Awaited<H>) => I,\n f9: (arg: Awaited<I>) => J,\n f10: (arg: Awaited<J>) => K,\n f11: (arg: Awaited<K>) => L,\n): PipeReturn<\n [\n typeof f1,\n typeof f2,\n typeof f3,\n typeof f4,\n typeof f5,\n typeof f6,\n typeof f7,\n typeof f8,\n typeof f9,\n typeof f10,\n typeof f11,\n ],\n A\n>\n// 12 functions\nexport function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(\n arg: A,\n f1: (arg: A) => B,\n f2: (arg: Awaited<B>) => C,\n f3: (arg: Awaited<C>) => D,\n f4: (arg: Awaited<D>) => E,\n f5: (arg: Awaited<E>) => F,\n f6: (arg: Awaited<F>) => G,\n f7: (arg: Awaited<G>) => H,\n f8: (arg: Awaited<H>) => I,\n f9: (arg: Awaited<I>) => J,\n f10: (arg: Awaited<J>) => K,\n f11: (arg: Awaited<K>) => L,\n f12: (arg: Awaited<L>) => M,\n): PipeReturn<\n [\n typeof f1,\n typeof f2,\n typeof f3,\n typeof f4,\n typeof f5,\n typeof f6,\n typeof f7,\n typeof f8,\n typeof f9,\n typeof f10,\n typeof f11,\n typeof f12,\n ],\n A\n>\n// 13 functions\nexport function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(\n arg: A,\n f1: (arg: A) => B,\n f2: (arg: Awaited<B>) => C,\n f3: (arg: Awaited<C>) => D,\n f4: (arg: Awaited<D>) => E,\n f5: (arg: Awaited<E>) => F,\n f6: (arg: Awaited<F>) => G,\n f7: (arg: Awaited<G>) => H,\n f8: (arg: Awaited<H>) => I,\n f9: (arg: Awaited<I>) => J,\n f10: (arg: Awaited<J>) => K,\n f11: (arg: Awaited<K>) => L,\n f12: (arg: Awaited<L>) => M,\n f13: (arg: Awaited<M>) => N,\n): PipeReturn<\n [\n typeof f1,\n typeof f2,\n typeof f3,\n typeof f4,\n typeof f5,\n typeof f6,\n typeof f7,\n typeof f8,\n typeof f9,\n typeof f10,\n typeof f11,\n typeof f12,\n typeof f13,\n ],\n A\n>\n// 14 functions\nexport function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(\n arg: A,\n f1: (arg: A) => B,\n f2: (arg: Awaited<B>) => C,\n f3: (arg: Awaited<C>) => D,\n f4: (arg: Awaited<D>) => E,\n f5: (arg: Awaited<E>) => F,\n f6: (arg: Awaited<F>) => G,\n f7: (arg: Awaited<G>) => H,\n f8: (arg: Awaited<H>) => I,\n f9: (arg: Awaited<I>) => J,\n f10: (arg: Awaited<J>) => K,\n f11: (arg: Awaited<K>) => L,\n f12: (arg: Awaited<L>) => M,\n f13: (arg: Awaited<M>) => N,\n f14: (arg: Awaited<N>) => O,\n): PipeReturn<\n [\n typeof f1,\n typeof f2,\n typeof f3,\n typeof f4,\n typeof f5,\n typeof f6,\n typeof f7,\n typeof f8,\n typeof f9,\n typeof f10,\n typeof f11,\n typeof f12,\n typeof f13,\n typeof f14,\n ],\n A\n>\n// 15 functions\nexport function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(\n arg: A,\n f1: (arg: A) => B,\n f2: (arg: Awaited<B>) => C,\n f3: (arg: Awaited<C>) => D,\n f4: (arg: Awaited<D>) => E,\n f5: (arg: Awaited<E>) => F,\n f6: (arg: Awaited<F>) => G,\n f7: (arg: Awaited<G>) => H,\n f8: (arg: Awaited<H>) => I,\n f9: (arg: Awaited<I>) => J,\n f10: (arg: Awaited<J>) => K,\n f11: (arg: Awaited<K>) => L,\n f12: (arg: Awaited<L>) => M,\n f13: (arg: Awaited<M>) => N,\n f14: (arg: Awaited<N>) => O,\n f15: (arg: Awaited<O>) => P,\n): PipeReturn<\n [\n typeof f1,\n typeof f2,\n typeof f3,\n typeof f4,\n typeof f5,\n typeof f6,\n typeof f7,\n typeof f8,\n typeof f9,\n typeof f10,\n typeof f11,\n typeof f12,\n typeof f13,\n typeof f14,\n typeof f15,\n ],\n A\n>\n// Implementation signature (fallback for 16+ functions)\n// oxlint-disable-next-line no-explicit-any\nexport function pipe<A, Fns extends [(arg: A) => any, ...λ[]]>(arg: A, ...fns: Fns): PipeReturn<Fns, A> {\n // @ts-expect-error - we want to use the any type here\n // oxlint-disable-next-line no-explicit-any, no-unsafe-return, no-unsafe-call, no-unsafe-type-assertion -- Required for pipe implementation\n return (flow(...(fns as [λ, ...λ[]])) as any)(arg)\n}\n"],"mappings":";;;AA6TA,SAAgB,KAA+C,KAAQ,GAAG,KAA8B;AAGtG,QAAQ,KAAK,GAAI,IAAoB,CAAS,IAAI"}
@@ -0,0 +1,2 @@
1
+ import { n as Predicate$1, r as Refinement, t as Predicate } from "../index-CcPnhWje.mjs";
2
+ export { Predicate, Predicate$1 as PredicateType, Refinement };
@@ -0,0 +1,3 @@
1
+ import { t as Predicate } from "../predicate-B6-EdVgW.mjs";
2
+
3
+ export { Predicate };