@barnum/barnum 0.3.0 → 0.4.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 (109) hide show
  1. package/artifacts/linux-arm64/barnum +0 -0
  2. package/artifacts/linux-x64/barnum +0 -0
  3. package/artifacts/macos-arm64/barnum +0 -0
  4. package/artifacts/macos-x64/barnum +0 -0
  5. package/artifacts/win-x64/barnum.exe +0 -0
  6. package/dist/all.d.ts +41 -10
  7. package/dist/all.d.ts.map +1 -0
  8. package/dist/all.js +1 -1
  9. package/dist/ast.d.ts +199 -98
  10. package/dist/ast.d.ts.map +1 -0
  11. package/dist/ast.js +271 -233
  12. package/dist/bind.d.ts +9 -12
  13. package/dist/bind.d.ts.map +1 -0
  14. package/dist/bind.js +14 -51
  15. package/dist/builtins/array.d.ts +36 -0
  16. package/dist/builtins/array.d.ts.map +1 -0
  17. package/dist/builtins/array.js +93 -0
  18. package/dist/builtins/index.d.ts +6 -0
  19. package/dist/builtins/index.d.ts.map +1 -0
  20. package/dist/builtins/index.js +5 -0
  21. package/dist/builtins/scalar.d.ts +12 -0
  22. package/dist/builtins/scalar.d.ts.map +1 -0
  23. package/dist/builtins/scalar.js +41 -0
  24. package/dist/builtins/struct.d.ts +25 -0
  25. package/dist/builtins/struct.d.ts.map +1 -0
  26. package/dist/builtins/struct.js +67 -0
  27. package/dist/builtins/tagged-union.d.ts +54 -0
  28. package/dist/builtins/tagged-union.d.ts.map +1 -0
  29. package/dist/builtins/tagged-union.js +81 -0
  30. package/dist/builtins/with-resource.d.ts +23 -0
  31. package/dist/builtins/with-resource.d.ts.map +1 -0
  32. package/dist/builtins/with-resource.js +35 -0
  33. package/dist/chain.d.ts +1 -0
  34. package/dist/chain.d.ts.map +1 -0
  35. package/dist/chain.js +3 -3
  36. package/dist/effect-id.d.ts +1 -0
  37. package/dist/effect-id.d.ts.map +1 -0
  38. package/dist/handler.d.ts +7 -6
  39. package/dist/handler.d.ts.map +1 -0
  40. package/dist/handler.js +5 -21
  41. package/dist/index.d.ts +10 -6
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +4 -2
  44. package/dist/iterator.d.ts +32 -0
  45. package/dist/iterator.d.ts.map +1 -0
  46. package/dist/iterator.js +123 -0
  47. package/dist/option.d.ts +74 -0
  48. package/dist/option.d.ts.map +1 -0
  49. package/dist/option.js +141 -0
  50. package/dist/pipe.d.ts +11 -10
  51. package/dist/pipe.d.ts.map +1 -0
  52. package/dist/pipe.js +5 -4
  53. package/dist/race.d.ts +5 -4
  54. package/dist/race.d.ts.map +1 -0
  55. package/dist/race.js +17 -42
  56. package/dist/recursive.d.ts +9 -3
  57. package/dist/recursive.d.ts.map +1 -0
  58. package/dist/recursive.js +18 -13
  59. package/dist/result.d.ts +50 -0
  60. package/dist/result.d.ts.map +1 -0
  61. package/dist/result.js +117 -0
  62. package/dist/run.d.ts +9 -2
  63. package/dist/run.d.ts.map +1 -0
  64. package/dist/run.js +37 -20
  65. package/dist/runtime.d.ts +6 -0
  66. package/dist/runtime.d.ts.map +1 -0
  67. package/dist/runtime.js +7 -0
  68. package/dist/schema.d.ts +1 -0
  69. package/dist/schema.d.ts.map +1 -0
  70. package/dist/schemas.d.ts +5 -0
  71. package/dist/schemas.d.ts.map +1 -0
  72. package/dist/schemas.js +13 -0
  73. package/dist/try-catch.d.ts +2 -1
  74. package/dist/try-catch.d.ts.map +1 -0
  75. package/dist/try-catch.js +10 -9
  76. package/dist/values.d.ts +6 -0
  77. package/dist/values.d.ts.map +1 -0
  78. package/dist/values.js +12 -0
  79. package/dist/worker.d.ts +5 -1
  80. package/dist/worker.d.ts.map +1 -0
  81. package/dist/worker.js +15 -3
  82. package/package.json +8 -6
  83. package/src/all.ts +118 -74
  84. package/src/ast.ts +773 -350
  85. package/src/bind.ts +32 -62
  86. package/src/builtins/array.ts +121 -0
  87. package/src/builtins/index.ts +17 -0
  88. package/src/builtins/scalar.ts +49 -0
  89. package/src/builtins/struct.ts +111 -0
  90. package/src/builtins/tagged-union.ts +142 -0
  91. package/src/builtins/with-resource.ts +69 -0
  92. package/src/chain.ts +4 -4
  93. package/src/handler.ts +12 -28
  94. package/src/index.ts +24 -17
  95. package/src/iterator.ts +243 -0
  96. package/src/option.ts +199 -0
  97. package/src/pipe.ts +123 -78
  98. package/src/race.ts +41 -51
  99. package/src/recursive.ts +44 -27
  100. package/src/result.ts +168 -0
  101. package/src/run.ts +53 -25
  102. package/src/runtime.ts +16 -0
  103. package/src/schemas.ts +21 -0
  104. package/src/try-catch.ts +14 -10
  105. package/src/values.ts +21 -0
  106. package/src/worker.ts +17 -2
  107. package/dist/builtins.d.ts +0 -257
  108. package/dist/builtins.js +0 -600
  109. package/src/builtins.ts +0 -804
package/dist/handler.d.ts CHANGED
@@ -26,19 +26,19 @@ export type Handler<TValue = unknown, TOutput = unknown> = TypedAction<TValue, T
26
26
  readonly __definition: UntypedHandlerDefinition;
27
27
  };
28
28
  /**
29
- * Handlers that return `Promise<void>` produce `never` output. This means
30
- * they naturally compose in pipes without needing `.drop()` a handler
31
- * that returns nothing produces a value no one can observe.
29
+ * Handlers that return `Promise<void>` produce `void` output (null at
30
+ * runtime). This is honest the handler completes and returns nothing
31
+ * useful, but execution continues.
32
32
  */
33
- type HandlerOutput<TOutput> = [TOutput] extends [void] ? never : TOutput;
34
- export declare function createHandler<TValue = never, TOutput = unknown>(definition: {
33
+ type HandlerOutput<TOutput> = [TOutput] extends [void] ? void : TOutput;
34
+ export declare function createHandler<TValue = void, TOutput = unknown>(definition: {
35
35
  inputValidator?: z.ZodType<TValue>;
36
36
  outputValidator?: z.ZodType<NoInfer<TOutput>>;
37
37
  handle: (context: {
38
38
  value: TValue;
39
39
  }) => Promise<TOutput>;
40
40
  }, exportName?: string): Handler<TValue, HandlerOutput<TOutput>>;
41
- export declare function createHandlerWithConfig<TValue = never, TOutput = unknown, TStepConfig = unknown>(definition: {
41
+ export declare function createHandlerWithConfig<TValue = void, TOutput = unknown, TStepConfig = unknown>(definition: {
42
42
  inputValidator?: z.ZodType<TValue>;
43
43
  outputValidator?: z.ZodType<NoInfer<TOutput>>;
44
44
  stepConfigValidator?: z.ZodType<TStepConfig>;
@@ -48,3 +48,4 @@ export declare function createHandlerWithConfig<TValue = never, TOutput = unknow
48
48
  }) => Promise<TOutput>;
49
49
  }, exportName?: string): (config: TStepConfig) => TypedAction<TValue, HandlerOutput<TOutput>>;
50
50
  export {};
51
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,KAAK,WAAW,EAAyB,MAAM,UAAU,CAAC;AAUnE,MAAM,WAAW,iBAAiB,CAChC,MAAM,GAAG,OAAO,EAChB,OAAO,GAAG,OAAO,EACjB,WAAW,GAAG,OAAO;IAErB,cAAc,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACnC,eAAe,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,mBAAmB,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,EAAE,CAAC,OAAO,EAAE;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,WAAW,CAAC;KACzB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACxB;AAED,wEAAwE;AACxE,UAAU,wBAAwB;IAChC,cAAc,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;IAC5B,mBAAmB,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;IAEhC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9C;AAMD,QAAA,M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MAAM,CAAC;QACd,UAAU,EAAE,WAAW,CAAC;KACzB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACxB,EACD,UAAU,CAAC,EAAE,MAAM,GAClB,CAAC,MAAM,EAAE,WAAW,KAAK,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC"}
package/dist/handler.js CHANGED
@@ -1,5 +1,8 @@
1
1
  import { fileURLToPath } from "node:url";
2
- import { typedAction } from "./ast.js";
2
+ import { toAction, typedAction } from "./ast.js";
3
+ import { chain } from "./chain.js";
4
+ import { all } from "./all.js";
5
+ import { constant, identity } from "./builtins/index.js";
3
6
  import { zodToCheckedJsonSchema } from "./schema.js";
4
7
  // ---------------------------------------------------------------------------
5
8
  // Handler — opaque typed handler reference
@@ -114,26 +117,7 @@ export function createHandlerWithConfig(definition, exportName) {
114
117
  // The factory function is the module export, so it must also carry
115
118
  // __definition for the worker to find (the worker imports the module
116
119
  // and accesses the named export, which is this function).
117
- const factory = (config) => typedAction({
118
- kind: "Chain",
119
- first: {
120
- kind: "All",
121
- actions: [
122
- {
123
- kind: "Invoke",
124
- handler: { kind: "Builtin", builtin: { kind: "Identity" } },
125
- },
126
- {
127
- kind: "Invoke",
128
- handler: {
129
- kind: "Builtin",
130
- builtin: { kind: "Constant", value: config },
131
- },
132
- },
133
- ],
134
- },
135
- rest: invokeAction,
136
- });
120
+ const factory = (config) => chain(toAction(all(identity(), constant(config))), toAction(invokeAction));
137
121
  Object.defineProperty(factory, HANDLER_BRAND, {
138
122
  value: true,
139
123
  enumerable: false,
package/dist/index.d.ts CHANGED
@@ -1,8 +1,12 @@
1
- import type { TaggedUnion, OptionDef, ResultDef } from "./ast.js";
1
+ import type { TaggedUnion, OptionDef, ResultDef, IteratorDef } from "./ast.js";
2
2
  export * from "./ast.js";
3
- export { constant, identity, drop, tag, merge, flatten, extractField, extractIndex, pick, dropResult, withResource, augment, tap, range, Option, Result, } from "./builtins.js";
4
- export * from "./handler.js";
5
- export { runPipeline } from "./run.js";
3
+ export { allObject, asOption, constant, drop, flatten, getField, getIndex, identity, panic, pick, range, splitFirst, splitLast, tag, taggedUnionSchema, withResource, wrapInField, } from "./builtins/index.js";
4
+ export { Option, first, last } from "./option.js";
5
+ export { Result } from "./result.js";
6
+ export { Iterator } from "./iterator.js";
7
+ export { runPipeline, type RunPipelineOptions, type LogLevel } from "./run.js";
6
8
  export { zodToCheckedJsonSchema } from "./schema.js";
7
- export type Option<T> = TaggedUnion<OptionDef<T>>;
8
- export type Result<TValue, TError> = TaggedUnion<ResultDef<TValue, TError>>;
9
+ export type Option<T> = TaggedUnion<"Option", OptionDef<T>>;
10
+ export type Result<TValue, TError> = TaggedUnion<"Result", ResultDef<TValue, TError>>;
11
+ export type Iterator<TElement> = TaggedUnion<"Iterator", IteratorDef<TElement>>;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE/E,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,KAAK,EACL,UAAU,EACV,SAAS,EACT,GAAG,EACH,iBAAiB,EACjB,YAAY,EACZ,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAKrD,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,WAAW,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,MAAM,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,WAAW,CAC9C,QAAQ,EACR,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAC1B,CAAC;AACF,MAAM,MAAM,QAAQ,CAAC,QAAQ,IAAI,WAAW,CAAC,UAAU,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from "./ast.js";
2
- export { constant, identity, drop, tag, merge, flatten, extractField, extractIndex, pick, dropResult, withResource, augment, tap, range, Option, Result, } from "./builtins.js";
3
- export * from "./handler.js";
2
+ export { allObject, asOption, constant, drop, flatten, getField, getIndex, identity, panic, pick, range, splitFirst, splitLast, tag, taggedUnionSchema, withResource, wrapInField, } from "./builtins/index.js";
3
+ export { Option, first, last } from "./option.js";
4
+ export { Result } from "./result.js";
5
+ export { Iterator } from "./iterator.js";
4
6
  export { runPipeline } from "./run.js";
5
7
  export { zodToCheckedJsonSchema } from "./schema.js";
@@ -0,0 +1,32 @@
1
+ import { type Iterator as IteratorT, type Option as OptionT, type Pipeable, type Result as ResultT, type TypedAction } from "./ast.js";
2
+ export declare const Iterator: {
3
+ /** Wrap an array as Iterator. `T[] → Iterator<T>` */
4
+ readonly fromArray: <TElement>() => TypedAction<TElement[], IteratorT<TElement>>;
5
+ /** Wrap an Option as Iterator. `Option<T> → Iterator<T>` */
6
+ readonly fromOption: <TElement>() => TypedAction<OptionT<TElement>, IteratorT<TElement>>;
7
+ /** Wrap a Result as Iterator (Ok kept, Err dropped). `Result<T, E> → Iterator<T>` */
8
+ readonly fromResult: <TElement, TError>() => TypedAction<ResultT<TElement, TError>, IteratorT<TElement>>;
9
+ /** Unwrap Iterator to array. `Iterator<T> → T[]` */
10
+ readonly collect: <TElement>() => TypedAction<IteratorT<TElement>, TElement[]>;
11
+ /** Transform each element. `Iterator<T> → Iterator<U>` */
12
+ readonly map: <TIn, TOut>(action: Pipeable<TIn, TOut>) => TypedAction<IteratorT<TIn>, IteratorT<TOut>>;
13
+ /** Flat-map each element. `f` returns any IntoIterator type. `Iterator<T> → Iterator<U>` */
14
+ readonly flatMap: <TIn, TOut>(action: Pipeable<TIn, unknown>) => TypedAction<IteratorT<TIn>, IteratorT<TOut>>;
15
+ /** Keep elements where predicate returns true. `Iterator<T> → Iterator<T>` */
16
+ readonly filter: <TElement>(predicate: Pipeable<TElement, boolean>) => TypedAction<IteratorT<TElement>, IteratorT<TElement>>;
17
+ /** Head/tail decomposition. `Iterator<T> → Option<[T, Iterator<T>]>` */
18
+ readonly splitFirst: <TElement>() => TypedAction<IteratorT<TElement>, OptionT<[TElement, IteratorT<TElement>]>>;
19
+ /** Init/last decomposition. `Iterator<T> → Option<[Iterator<T>, T]>` */
20
+ readonly splitLast: <TElement>() => TypedAction<IteratorT<TElement>, OptionT<[IteratorT<TElement>, TElement]>>;
21
+ /** Fold elements with accumulator. `Iterator<T> → TAcc` */
22
+ readonly fold: <TElement, TAcc>(init: Pipeable<void, TAcc>, body: Pipeable<[TAcc, TElement], TAcc>) => TypedAction<IteratorT<TElement>, TAcc>;
23
+ /** Slice elements from start to end. `Iterator<T> → Iterator<T>` */
24
+ readonly slice: <TElement>(start: number, end?: number) => TypedAction<IteratorT<TElement>, IteratorT<TElement>>;
25
+ /** First n elements. `Iterator<T> → Iterator<T>` */
26
+ readonly take: <TElement>(n: number) => TypedAction<IteratorT<TElement>, IteratorT<TElement>>;
27
+ /** Drop first n elements. `Iterator<T> → Iterator<T>` */
28
+ readonly skip: <TElement>(n: number) => TypedAction<IteratorT<TElement>, IteratorT<TElement>>;
29
+ /** Check if iterator is empty. `Iterator<T> → boolean` */
30
+ readonly isEmpty: <TElement>() => TypedA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SAAS,CAAC,QAAQ,CAAC,CAAC;IAcxD,wEAAwE;0BAC7D,QAAQ,OAAK,WAAW,CACjC,SAAS,CAAC,QAAQ,CAAC,EACnB,OAAO,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CACzC;IAaD,wEAAwE;yBAC9D,QAAQ,OAAK,WAAW,CAChC,SAAS,CAAC,QAAQ,CAAC,EACnB,OAAO,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,CACzC;IAaD,2DAA2D;oBACtD,QAAQ,EAAE,IAAI,QACX,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,QACpB,QAAQ,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,IAAI,CAAC,KACrC,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC;IAyCzC,oEAAoE;qBAC9D,QAAQ,SACL,MAAM,QACP,MAAM,KACX,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IAUxD,oDAAoD;oBAC/C,QAAQ,KACR,MAAM,KACR,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IAIxD,yDAAyD;oBACpD,QAAQ,KACR,MAAM,KACR,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IAIxD,0DAA0D;uBAClD,QAAQ,OAAK,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAGtD,CAAC"}
@@ -0,0 +1,123 @@
1
+ import { toAction, typedAction, branch, branchFamily, forEach, loop, } from "./ast.js";
2
+ import { chain } from "./chain.js";
3
+ import { constant, drop, flatten, getField, getIndex, identity, slice, splitFirst, splitLast, tag, } from "./builtins/index.js";
4
+ import { all } from "./all.js";
5
+ import { Option } from "./option.js";
6
+ import { bindInput } from "./bind.js";
7
+ // ---------------------------------------------------------------------------
8
+ // Helpers
9
+ // ---------------------------------------------------------------------------
10
+ /**
11
+ * Wrap a single value in an array. `T → T[]`
12
+ * Implemented as `all(identity())`. May warrant a dedicated builtin later.
13
+ */
14
+ function wrapInArray() {
15
+ return all(identity());
16
+ }
17
+ /**
18
+ * Normalize any IntoIterator return type to a plain array.
19
+ * Used inside `.flatMap()` to handle Iterator, Option, Result, and Array returns.
20
+ */
21
+ const intoIteratorNormalize = branchFamily({
22
+ Iterator: branch({ Iterator: identity() }),
23
+ Option: branch({ Some: wrapInArray(), None: constant([]) }),
24
+ Result: branch({ Ok: wrapInArray(), Err: constant([]) }),
25
+ Array: identity(),
26
+ });
27
+ // ---------------------------------------------------------------------------
28
+ // Iterator namespace
29
+ // ---------------------------------------------------------------------------
30
+ export const Iterator = {
31
+ /** Wrap an array as Iterator. `T[] → Iterator<T>` */
32
+ fromArray() {
33
+ return tag("Iterator", "Iterator");
34
+ },
35
+ /** Wrap an Option as Iterator. `Option<T> → Iterator<T>` */
36
+ fromOption() {
37
+ return branch({
38
+ Some: chain(wrapInArray(), Iterator.fromArray()),
39
+ None: chain(constant([]), Iterator.fromArray()),
40
+ });
41
+ },
42
+ /** Wrap a Result as Iterator (Ok kept, Err dropped). `Result<T, E> → Iterator<T>` */
43
+ fromResult() {
44
+ return branch({
45
+ Ok: chain(wrapInArray(), Iterator.fromArray()),
46
+ Err: chain(constant([]), Iterator.fromArray()),
47
+ });
48
+ },
49
+ /** Unwrap Iterator to array. `Iterator<T> → T[]` */
50
+ collect() {
51
+ return getField("value");
52
+ },
53
+ /** Transform each element. `Iterator<T> → Iterator<U>` */
54
+ map(action) {
55
+ return chain(toAction(getField("value")), chain(toAction(forEach(action)), Iterator.fromArray()));
56
+ },
57
+ /** Flat-map each element. `f` returns any IntoIterator type. `Iterator<T> → Iterator<U>` */
58
+ flatMap(action) {
59
+ return chain(toAction(getField("value")), chain(toAction(forEach(chain(action, intoIteratorNormalize))), chain(toAction(flatten()), Iterator.fromArray())));
60
+ },
61
+ /** Keep elements where predicate returns true. `Iterator<T> → Iterator<T>` */
62
+ filter(predicate) {
63
+ return Iterator.flatMap(bindInput((element) => element
64
+ .then(predicate)
65
+ .asOption()
66
+ .branch({
67
+ Some: element.some(),
68
+ None: chain(drop, Option.none()),
69
+ })));
70
+ },
71
+ /** Head/tail decomposition. `Iterator<T> → Option<[T, Iterator<T>]>` */
72
+ splitFirst() {
73
+ return Iterator.collect()
74
+ .then(splitFirst())
75
+ .then(Option.map(all(getIndex(0).unwrap(), getIndex(1).unwrap().iterate())));
76
+ },
77
+ /** Init/last decomposition. `Iterator<T> → Option<[Iterator<T>, T]>` */
78
+ splitLast() {
79
+ return Iterator.collect()
80
+ .then(splitLast())
81
+ .then(Option.map(all(getIndex(0).unwrap().iterate(), getIndex(1).unwrap())));
82
+ },
83
+ /** Fold elements with accumulator. `Iterator<T> → TAcc` */
84
+ fold(init, body) {
85
+ return Iterator.collect().then(bindInput((elements) => all(init, elements).then(loop((recur, done) => {
86
+ // Re-wrap done to bridge VoidToNull<TAcc> → TAcc (TypeScript
87
+ // can't simplify the conditional type for generic TAcc).
88
+ const doneTAcc = typedAction(toAction(done));
89
+ // Wrap return with typedAction — branch output inference fails
90
+ // for generic types inside loop bodies.
91
+ return typedAction(toAction(bindInput((state) => {
92
+ const acc = state.getIndex(0).unwrap();
93
+ const remaining = state.getIndex(1).unwrap();
94
+ return remaining.splitFirst().branch({
95
+ None: acc.then(doneTAcc),
96
+ Some: bindInput((headTail) => {
97
+ const head = headTail.getIndex(0).unwrap();
98
+ const tail = headTail.getIndex(1).unwrap();
99
+ return all(acc, head)
100
+ .then(body)
101
+ .then(bindInput((newAcc) => all(newAcc, tail).then(recur)));
102
+ }),
103
+ });
104
+ })));
105
+ }))));
106
+ },
107
+ /** Slice elements from start to end. `Iterator<T> → Iterator<T>` */
108
+ slice(start, end) {
109
+ return chain(Iterator.collect(), chain(toAction(slice(start, end)), Iterator.fromArray()));
110
+ },
111
+ /** First n elements. `Iterator<T> → Iterator<T>` */
112
+ take(n) {
113
+ return Iterator.slice(0, n);
114
+ },
115
+ /** Drop first n elements. `Iterator<T> → Iterator<T>` */
116
+ skip(n) {
117
+ return Iterator.slice(n);
118
+ },
119
+ /** Check if iterator is empty. `Iterator<T> → boolean` */
120
+ isEmpty() {
121
+ return Iterator.collect().splitFirst().isNone();
122
+ },
123
+ };
@@ -0,0 +1,74 @@
1
+ import { type Option as OptionT, type Pipeable, type Result as ResultT, type TypedAction } from "./ast.js";
2
+ /**
3
+ * Option namespace. All combinators produce TypedAction AST nodes that
4
+ * desugar to branch + existing builtins, except collect which uses the
5
+ * CollectSome builtin.
6
+ */
7
+ export declare const Option: {
8
+ /** Tag combinator: wrap value as `Option.Some`. `T → Option<T>` */
9
+ readonly some: <T>() => TypedAction<T, OptionT<T>>;
10
+ /** Tag combinator: wrap value as `Option.None`. `void → Option<T>` */
11
+ readonly none: <T>() => TypedAction<void, OptionT<T>>;
12
+ /** Transform the Some value. `Option<T> → Option<U>` */
13
+ readonly map: <T, U>(action: Pipeable<T, U>) => TypedAction<OptionT<T>, OptionT<U>>;
14
+ /**
15
+ * Monadic bind (flatMap). If Some, pass the value to action which
16
+ * returns Option<U>. If None, stay None. `Option<T> → Option<U>`
17
+ */
18
+ readonly andThen: <T, U>(action: Pipeable<T, OptionT<U>>) => TypedAction<OptionT<T>, OptionT<U>>;
19
+ /**
20
+ * Extract the Some value or panic. `Option<T> → T`
21
+ *
22
+ * Panics (fatal, not caught by tryCatch) if the value is None.
23
+ */
24
+ readonly unwrap: <T>() => TypedAction<OptionT<T>, T>;
25
+ /**
26
+ * Extract the Some value or produce a default from an action.
27
+ * `Option<T> → T`
28
+ */
29
+ readonly unwrapOr: <T>(defaultAction: Pipeable<void, T>) => TypedAction<OptionT<T>, T>;
30
+ /**
31
+ * Conditional keep. If Some, pass value to predicate which returns
32
+ * Option<T>. If None, stay None. `Option<T> → Option<T>`
33
+ */
34
+ readonly filter: <T>(predicate: Pipeable<T, OptionT<T>>) => TypedAction<OptionT<T>, OptionT<T>>;
35
+ /**
36
+ * Collect Some values from an array, discarding Nones.
37
+ * `Option<T>[] → T[]`
38
+ */
39
+ readonly collect: <T = any>() => TypedAction<OptionT<T>[], T[]>;
40
+ /**
41
+ * Test if the value is Some. `Option<T> → boolean`
42
+ */
43
+ readonly isSome: <T>() => TypedAction<OptionT<T>, boolean>;
44
+ /**
45
+ * Test if the value is None. `Option<T> → boolean`
46
+ */
47
+ readonly isNone: <T>() => TypedAction<OptionT<T>, boolean>;
48
+ /**
49
+ * Swap Option/Result nesting.
50
+ * `Option<Result<TValue, TError>> → Result<Option<TValue>, TError>`
51
+ *
52
+ * - Some(Ok(t)) → Ok(Some(t))
53
+ * - Some(Err(e)) → Err(e)
54
+ * - None → Ok(None)
55
+ */
56
+ readonly transpose: <TValue, TError>() => TypedAction<OptionT<ResultT<TValue, TError>>, ResultT<OptionT<TValue>, TError>>;
57
+ };
58
+ /**
59
+ * Extract the first element of an array.
60
+ * `readonly TElement[] → Option<TElement>`
61
+ *
62
+ * Composes `splitFirst` (which returns `Option<[TElement, TElement[]]>`)
63
+ * with `Option.map(getIndex(0))` to extract just the element.
64
+ */
65
+ export declare function first<TElement>(): TypedAction<readonly TElement[], OptionT<TElement>>;
66
+ /**
67
+ * Extract the last element of an array.
68
+ * `readonly TElement[] → Option<TElement>`
69
+ *
70
+ * Composes `splitLast` (which returns `Option<[TElement[], TElement]>`)
71
+ * with `Option.map(getIndex(1))` to extract just the element.
72
+ */
73
+ export declare function last<TElement>(): TypedAction<readonly TElement[], OptionT<TElement>>;
74
+ //# sourceMappingURL=option.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option.d.ts","sourceRoot":"","sources":["../src/option.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,IAAI,OAAO,EAEtB,KAAK,QAAQ,EACb,KAAK,MAAM,IAAI,OAAO,EACtB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AAC,CAAC,EAAE,OAAO,CAAC;IAO7C;;;;;;;OAOG;yBACO,MAAM,EAAE,MAAM,OAAK,WAAW,CACtC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAChC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CACjC;CAeO,CAAC;AAMX;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,QAAQ,KAAK,WAAW,CAC5C,SAAS,QAAQ,EAAE,EACnB,OAAO,CAAC,QAAQ,CAAC,CAClB,CAKA;AAMD;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,QAAQ,KAAK,WAAW,CAC3C,SAAS,QAAQ,EAAE,EACnB,OAAO,CAAC,QAAQ,CAAC,CAClB,CAKA"}
package/dist/option.js ADDED
@@ -0,0 +1,141 @@
1
+ import { toAction, typedAction, branch, } from "./ast.js";
2
+ import { chain } from "./chain.js";
3
+ import { constant, drop, getIndex, identity, panic, splitFirst, splitLast, tag, } from "./builtins/index.js";
4
+ import { Result } from "./result.js";
5
+ // ---------------------------------------------------------------------------
6
+ // Option namespace — combinators for Option<T> tagged unions
7
+ // ---------------------------------------------------------------------------
8
+ /**
9
+ * Option namespace. All combinators produce TypedAction AST nodes that
10
+ * desugar to branch + existing builtins, except collect which uses the
11
+ * CollectSome builtin.
12
+ */
13
+ export const Option = {
14
+ /** Tag combinator: wrap value as `Option.Some`. `T → Option<T>` */
15
+ some() {
16
+ return tag("Some", "Option");
17
+ },
18
+ /** Tag combinator: wrap value as `Option.None`. `void → Option<T>` */
19
+ none() {
20
+ return tag("None", "Option");
21
+ },
22
+ /** Transform the Some value. `Option<T> → Option<U>` */
23
+ map(action) {
24
+ return branch({
25
+ Some: chain(action, Option.some()),
26
+ None: Option.none(),
27
+ });
28
+ },
29
+ /**
30
+ * Monadic bind (flatMap). If Some, pass the value to action which
31
+ * returns Option<U>. If None, stay None. `Option<T> → Option<U>`
32
+ */
33
+ andThen(action) {
34
+ return branch({
35
+ Some: action,
36
+ None: Option.none(),
37
+ });
38
+ },
39
+ /**
40
+ * Extract the Some value or panic. `Option<T> → T`
41
+ *
42
+ * Panics (fatal, not caught by tryCatch) if the value is None.
43
+ */
44
+ unwrap() {
45
+ return branch({
46
+ Some: identity(),
47
+ None: panic("called unwrap on None"),
48
+ });
49
+ },
50
+ /**
51
+ * Extract the Some value or produce a default from an action.
52
+ * `Option<T> → T`
53
+ */
54
+ unwrapOr(defaultAction) {
55
+ return branch({
56
+ Some: identity(),
57
+ None: defaultAction,
58
+ });
59
+ },
60
+ /**
61
+ * Conditional keep. If Some, pass value to predicate which returns
62
+ * Option<T>. If None, stay None. `Option<T> → Option<T>`
63
+ */
64
+ filter(predicate) {
65
+ return branch({
66
+ Some: predicate,
67
+ None: Option.none(),
68
+ });
69
+ },
70
+ /**
71
+ * Collect Some values from an array, discarding Nones.
72
+ * `Option<T>[] → T[]`
73
+ */
74
+ collect() {
75
+ return typedAction({
76
+ kind: "Invoke",
77
+ handler: { kind: "Builtin", builtin: { kind: "CollectSome" } },
78
+ });
79
+ },
80
+ /**
81
+ * Test if the value is Some. `Option<T> → boolean`
82
+ */
83
+ isSome() {
84
+ return branch({
85
+ Some: constant(true),
86
+ None: constant(false),
87
+ });
88
+ },
89
+ /**
90
+ * Test if the value is None. `Option<T> → boolean`
91
+ */
92
+ isNone() {
93
+ return branch({
94
+ Some: constant(false),
95
+ None: constant(true),
96
+ });
97
+ },
98
+ /**
99
+ * Swap Option/Result nesting.
100
+ * `Option<Result<TValue, TError>> → Result<Option<TValue>, TError>`
101
+ *
102
+ * - Some(Ok(t)) → Ok(Some(t))
103
+ * - Some(Err(e)) → Err(e)
104
+ * - None → Ok(None)
105
+ */
106
+ transpose() {
107
+ return branch({
108
+ Some: branch({
109
+ Ok: chain(Option.some(), Result.ok()),
110
+ Err: Result.err(),
111
+ }),
112
+ None: chain(chain(drop, Option.none()), Result.ok()),
113
+ });
114
+ },
115
+ };
116
+ // ---------------------------------------------------------------------------
117
+ // First — extract the first element of an array as Option<TElement>
118
+ // ---------------------------------------------------------------------------
119
+ /**
120
+ * Extract the first element of an array.
121
+ * `readonly TElement[] → Option<TElement>`
122
+ *
123
+ * Composes `splitFirst` (which returns `Option<[TElement, TElement[]]>`)
124
+ * with `Option.map(getIndex(0))` to extract just the element.
125
+ */
126
+ export function first() {
127
+ return chain(toAction(splitFirst()), toAction(Option.map(toAction(getIndex(0).unwrap()))));
128
+ }
129
+ // ---------------------------------------------------------------------------
130
+ // Last — extract the last element of an array as Option<TElement>
131
+ // ---------------------------------------------------------------------------
132
+ /**
133
+ * Extract the last element of an array.
134
+ * `readonly TElement[] → Option<TElement>`
135
+ *
136
+ * Composes `splitLast` (which returns `Option<[TElement[], TElement]>`)
137
+ * with `Option.map(getIndex(1))` to extract just the element.
138
+ */
139
+ export function last() {
140
+ return chain(toAction(splitLast()), toAction(Option.map(toAction(getIndex(1).unwrap()))));
141
+ }
package/dist/pipe.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { type PipeIn, type Pipeable, type TypedAction } from "./ast.js";
2
- export declare function pipe<T1, T2>(a1: Pipeable<T1, T2>): TypedAction<PipeIn<T1>, T2>;
3
- export declare function pipe<T1, T2, T3>(a1: Pipeable<T1, T2>, a2: Pipeable<T2, T3>): TypedAction<PipeIn<T1>, T3>;
4
- export declare function pipe<T1, T2, T3, T4>(a1: Pipeable<T1, T2>, a2: Pipeable<T2, T3>, a3: Pipeable<T3, T4>): TypedAction<PipeIn<T1>, T4>;
5
- export declare function pipe<T1, T2, T3, T4, T5>(a1: Pipeable<T1, T2>, a2: Pipeable<T2, T3>, a3: Pipeable<T3, T4>, a4: Pipeable<T4, T5>): TypedAction<PipeIn<T1>, T5>;
6
- export declare function pipe<T1, T2, T3, T4, T5, T6>(a1: Pipeable<T1, T2>, a2: Pipeable<T2, T3>, a3: Pipeable<T3, T4>, a4: Pipeable<T4, T5>, a5: Pipeable<T5, T6>): TypedAction<PipeIn<T1>, T6>;
7
- export declare function pipe<T1, T2, T3, T4, T5, T6, T7>(a1: Pipeable<T1, T2>, a2: Pipeable<T2, T3>, a3: Pipeable<T3, T4>, a4: Pipeable<T4, T5>, a5: Pipeable<T5, T6>, a6: Pipeable<T6, T7>): TypedAction<PipeIn<T1>, T7>;
8
- export declare function pipe<T1, T2, T3, T4, T5, T6, T7, T8>(a1: Pipeable<T1, T2>, a2: Pipeable<T2, T3>, a3: Pipeable<T3, T4>, a4: Pipeable<T4, T5>, a5: Pipeable<T5, T6>, a6: Pipeable<T6, T7>, a7: Pipeable<T7, T8>): TypedAction<PipeIn<T1>, T8>;
9
- export declare function pipe<T1, T2, T3, T4, T5, T6, T7, T8, T9>(a1: Pipeable<T1, T2>, a2: Pipeable<T2, T3>, a3: Pipeable<T3, T4>, a4: Pipeable<T4, T5>, a5: Pipeable<T5, T6>, a6: Pipeable<T6, T7>, a7: Pipeable<T7, T8>, a8: Pipeable<T8, T9>): TypedAction<PipeIn<T1>, T9>;
10
- export declare function pipe<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(a1: Pipeable<T1, T2>, a2: Pipeable<T2, T3>, a3: Pipeable<T3, T4>, a4: Pipeable<T4, T5>, a5: Pipeable<T5, T6>, a6: Pipeable<T6, T7>, a7: Pipeable<T7, T8>, a8: Pipeable<T8, T9>, a9: Pipeable<T9, T10>): TypedAction<PipeIn<T1>, T10>;
11
- export declare function pipe<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(a1: Pipeable<T1, T2>, a2: Pipeable<T2, T3>, a3: Pipeable<T3, T4>, a4: Pipeable<T4, T5>, a5: Pipeable<T5, T6>, a6: Pipeable<T6, T7>, a7: Pipeable<T7, T8>, a8: Pipeable<T8, T9>, a9: Pipeable<T9, T10>, a10: Pipeable<T10, T11>): TypedAction<PipeIn<T1>, T11>;
2
+ export declare function pipe<TStep1, TStep2>(a1: Pipeable<TStep1, TStep2>): TypedAction<PipeIn<TStep1>, TStep2>;
3
+ export declare function pipe<TStep1, TStep2, TStep3>(a1: Pipeable<TStep1, TStep2>, a2: Pipeable<TStep2, TStep3>): TypedAction<PipeIn<TStep1>, TStep3>;
4
+ export declare function pipe<TStep1, TStep2, TStep3, TStep4>(a1: Pipeable<TStep1, TStep2>, a2: Pipeable<TStep2, TStep3>, a3: Pipeable<TStep3, TStep4>): TypedAction<PipeIn<TStep1>, TStep4>;
5
+ export declare function pipe<TStep1, TStep2, TStep3, TStep4, TStep5>(a1: Pipeable<TStep1, TStep2>, a2: Pipeable<TStep2, TStep3>, a3: Pipeable<TStep3, TStep4>, a4: Pipeable<TStep4, TStep5>): TypedAction<PipeIn<TStep1>, TStep5>;
6
+ export declare function pipe<TStep1, TStep2, TStep3, TStep4, TStep5, TStep6>(a1: Pipeable<TStep1, TStep2>, a2: Pipeable<TStep2, TStep3>, a3: Pipeable<TStep3, TStep4>, a4: Pipeable<TStep4, TStep5>, a5: Pipeable<TStep5, TStep6>): TypedAction<PipeIn<TStep1>, TStep6>;
7
+ export declare function pipe<TStep1, TStep2, TStep3, TStep4, TStep5, TStep6, TStep7>(a1: Pipeable<TStep1, TStep2>, a2: Pipeable<TStep2, TStep3>, a3: Pipeable<TStep3, TStep4>, a4: Pipeable<TStep4, TStep5>, a5: Pipeable<TStep5, TStep6>, a6: Pipeable<TStep6, TStep7>): TypedAction<PipeIn<TStep1>, TStep7>;
8
+ export declare function pipe<TStep1, TStep2, TStep3, TStep4, TStep5, TStep6, TStep7, TStep8>(a1: Pipeable<TStep1, TStep2>, a2: Pipeable<TStep2, TStep3>, a3: Pipeable<TStep3, TStep4>, a4: Pipeable<TStep4, TStep5>, a5: Pipeable<TStep5, TStep6>, a6: Pipeable<TStep6, TStep7>, a7: Pipeable<TStep7, TStep8>): TypedAction<PipeIn<TStep1>, TStep8>;
9
+ export declare function pipe<TStep1, TStep2, TStep3, TStep4, TStep5, TStep6, TStep7, TStep8, TStep9>(a1: Pipeable<TStep1, TStep2>, a2: Pipeable<TStep2, TStep3>, a3: Pipeable<TStep3, TStep4>, a4: Pipeable<TStep4, TStep5>, a5: Pipeable<TStep5, TStep6>, a6: Pipeable<TStep6, TStep7>, a7: Pipeable<TStep7, TStep8>, a8: Pipeable<TStep8, TStep9>): TypedAction<PipeIn<TStep1>, TStep9>;
10
+ export declare function pipe<TStep1, TStep2, TStep3, TStep4, TStep5, TStep6, TStep7, TStep8, TStep9, TStep10>(a1: Pipeable<TStep1, TStep2>, a2: Pipeable<TStep2, TStep3>, a3: Pipeable<TStep3, TStep4>, a4: Pipeable<TStep4, TStep5>, a5: Pipeable<TStep5, TStep6>, a6: Pipeable<TStep6, TStep7>, a7: Pipeable<TStep7, TStep8>, a8: Pipeable<TStep8, TStep9>, a9: Pipeable<TStep9, TStep10>): TypedAction<PipeIn<TStep1>, TStep10>;
11
+ export declare function pipe<TStep1, TStep2, TStep3, TStep4, TStep5, TStep6, TStep7, TStep8, TStep9, TStep10, TStep11>(a1: Pipeable<TStep1, TStep2>, a2: Pipeable<TStep2, TStep3>, a3: Pipeable<TStep3, TStep4>, a4: Pipeable<TStep4, TStep5>, a5: Pipeable<TStep5, TStep6>, a6: Pipeable<TStep6, TStep7>, a7: Pipeable<TStep7, TStep8>, a8: Pipeable<TStep8, TStep9>, a9: Pipeable<TStep9, TStep10>, a10: Pipeable<TStep10, TStep11>): TypedAction<PipeIn<TStep1>, TStep11>;
12
+ //# sourceMappingURL=pipe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipe.d.ts","sourceRoot":"","sources":["../src/pipe.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,WAAW,EAEjB,MAAM,UAAU,CAAC;AAIlB,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EACjC,EAAE,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3B,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;AACvC,wBAAgB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,GAC5B,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;AACxC,wBAAgB,IAAI,CAClB,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,OAAO,EACP,OAAO,EAEP,EAAE,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,EAAE,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,EAAE,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,EAAE,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,EAAE,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,EAAE,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,EAAE,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,EAAE,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,EAAE,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,GAAG,EAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,GAC9B,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC"}
package/dist/pipe.js CHANGED
@@ -1,11 +1,12 @@
1
- import { typedAction, } from "./ast.js";
2
- import { identity } from "./builtins.js";
1
+ import { toAction, } from "./ast.js";
2
+ import { chain } from "./chain.js";
3
+ import { identity } from "./builtins/index.js";
3
4
  export function pipe(...actions) {
4
5
  if (actions.length === 0) {
5
- return identity;
6
+ return identity();
6
7
  }
7
8
  if (actions.length === 1) {
8
9
  return actions[0];
9
10
  }
10
- return actions.reduceRight((rest, first) => typedAction({ kind: "Chain", first, rest }));
11
+ return actions.reduceRight((rest, first) => toAction(chain(toAction(first), toAction(rest))));
11
12
  }
package/dist/race.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Pipeable, type Result, type TypedAction } from "./ast.js";
1
+ import { type Pipeable, type Result as ResultT, type TypedAction } from "./ast.js";
2
2
  /**
3
3
  * Run multiple actions concurrently. The first to complete wins; losers
4
4
  * are cancelled during `RestartHandle` frame teardown.
@@ -8,7 +8,7 @@ import { type Pipeable, type Result, type TypedAction } from "./ast.js";
8
8
  *
9
9
  * Compiled form (restart+Branch, same substrate as loop/earlyReturn):
10
10
  * `Chain(Tag("Continue"),`
11
- * `RestartHandle(id, ExtractIndex(0),`
11
+ * `RestartHandle(id, GetIndex(0),`
12
12
  * `Branch({`
13
13
  * `Continue: All(Chain(a, breakPerform), Chain(b, breakPerform), ...),`
14
14
  * `Break: identity,`
@@ -26,7 +26,7 @@ export declare function race<TIn, TOut>(...actions: Pipeable<TIn, TOut>[]): Type
26
26
  *
27
27
  * To preserve data across a sleep, use `bindInput`.
28
28
  */
29
- export declare function sleep(ms: number): TypedAction<any, never>;
29
+ export declare function sleep(ms: number): TypedAction<any, void>;
30
30
  /**
31
31
  * @internal TypeScript handler that takes ms as pipeline input and returns
32
32
  * void after the timer fires. Used by `withTimeout` where the duration
@@ -50,4 +50,5 @@ export declare function dynamicSleep(): void;
50
50
  * Same restart+Branch substrate as race: each branch tags Break after
51
51
  * wrapping its result as Ok or Err.
52
52
  */
53
- export declare function withTimeout<TIn, TOut>(ms: Pipeable<TIn, number>, body: Pipeable<TIn, TOut>): TypedAction<TIn, Result<TOut, void>>;
53
+ export declare function withTimeout<TIn, TOut>(ms: Pipeable<TIn, number>, body: Pipeable<TIn, TOut>): TypedAction<TIn, ResultT<TOut, void>>;
54
+ //# sourceMappingURL=race.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"race.d.ts","sourceRoot":"","sources":["../src/race.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,EAIjB,MAAM,UAAU,CAAC;AA2BlB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,IAAI,EAC5B,GAAG,OAAO,EAAE,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,GAChC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAaxB;AAMD;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAKxD;AAgBD;;;;GAIG;AAEH,wBAAgB,YAAY,IAAI,IAAI,CAAG;AAavC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,IAAI,EACnC,EAAE,EAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,EACzB,IAAI,EAAE,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,GACxB,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CA8BvC"}