@nicolastoulemont/std 0.9.0 → 0.11.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.
- package/README.md +406 -69
- package/dist/brand/index.d.mts +1 -1
- package/dist/brand/index.mjs +1 -1
- package/dist/{brand-DZgGDrAe.mjs → brand-DP-C92GS.mjs} +2 -2
- package/dist/{brand-DZgGDrAe.mjs.map → brand-DP-C92GS.mjs.map} +1 -1
- package/dist/{brand.types-B3NDX1vo.d.mts → brand.types-Cqkibdlt.d.mts} +1 -1
- package/dist/{brand.types-B3NDX1vo.d.mts.map → brand.types-Cqkibdlt.d.mts.map} +1 -1
- package/dist/context/index.d.mts +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{context-0xDbwtpx.mjs → context-7oKePrBY.mjs} +2 -2
- package/dist/{context-0xDbwtpx.mjs.map → context-7oKePrBY.mjs.map} +1 -1
- package/dist/{context-B2dWloPl.d.mts → context-C9UX6GJo.d.mts} +2 -2
- package/dist/{context-B2dWloPl.d.mts.map → context-C9UX6GJo.d.mts.map} +1 -1
- package/dist/data/index.d.mts +1 -1
- package/dist/data/index.mjs +1 -1
- package/dist/data-W10ldR5l.mjs +2 -0
- package/dist/data-W10ldR5l.mjs.map +1 -0
- package/dist/{dual-fN6OUwN_.mjs → dual-CZhzZslG.mjs} +1 -1
- package/dist/{dual-fN6OUwN_.mjs.map → dual-CZhzZslG.mjs.map} +1 -1
- package/dist/duration/index.d.mts +1 -1
- package/dist/duration/index.mjs +1 -1
- package/dist/{duration-Bas3mi1N.mjs → duration-Dwtjy95Z.mjs} +2 -2
- package/dist/{duration-Bas3mi1N.mjs.map → duration-Dwtjy95Z.mjs.map} +1 -1
- package/dist/either/index.d.mts +1 -1
- package/dist/either/index.mjs +1 -1
- package/dist/{either-G7uOu4Ar.mjs → either-B2TvVY_j.mjs} +2 -2
- package/dist/{either-G7uOu4Ar.mjs.map → either-B2TvVY_j.mjs.map} +1 -1
- package/dist/exit-D5zZVlCn.d.mts +67 -0
- package/dist/exit-D5zZVlCn.d.mts.map +1 -0
- package/dist/fiber/index.d.mts +2 -0
- package/dist/fiber/index.mjs +1 -0
- package/dist/fiber-CZsyrDdd.mjs +2 -0
- package/dist/fiber-CZsyrDdd.mjs.map +1 -0
- package/dist/{flow-CNyLsPGb.mjs → flow-D8_tllWl.mjs} +1 -1
- package/dist/{flow-CNyLsPGb.mjs.map → flow-D8_tllWl.mjs.map} +1 -1
- package/dist/functions/index.d.mts +1 -1
- package/dist/functions/index.mjs +1 -1
- package/dist/functions-DmOZ7O4j.mjs +2 -0
- package/dist/{functions-ByAk682_.mjs.map → functions-DmOZ7O4j.mjs.map} +1 -1
- package/dist/fx/index.d.mts +1 -1
- package/dist/fx/index.mjs +1 -1
- package/dist/fx-DXBw4iYX.mjs +2 -0
- package/dist/fx-DXBw4iYX.mjs.map +1 -0
- package/dist/fx.runtime-B2_rL7h_.mjs +2 -0
- package/dist/fx.runtime-B2_rL7h_.mjs.map +1 -0
- package/dist/fx.runtime-q661ckFI.d.mts +16 -0
- package/dist/fx.runtime-q661ckFI.d.mts.map +1 -0
- package/dist/{fx.types-DyQVgTS8.mjs → fx.types-Bg-Mmdm5.mjs} +1 -1
- package/dist/{fx.types-DyQVgTS8.mjs.map → fx.types-Bg-Mmdm5.mjs.map} +1 -1
- package/dist/{fx.types-BdN1EWxr.d.mts → fx.types-CpFKa-Jj.d.mts} +1 -1
- package/dist/{fx.types-BdN1EWxr.d.mts.map → fx.types-CpFKa-Jj.d.mts.map} +1 -1
- package/dist/{index-DfAqfnY0.d.mts → index-BJiD1-T_.d.mts} +4 -4
- package/dist/{index-DfAqfnY0.d.mts.map → index-BJiD1-T_.d.mts.map} +1 -1
- package/dist/{index-DR7hzXU4.d.mts → index-BR6lwlNv.d.mts} +137 -29
- package/dist/index-BR6lwlNv.d.mts.map +1 -0
- package/dist/index-BfQSp6pV.d.mts +226 -0
- package/dist/index-BfQSp6pV.d.mts.map +1 -0
- package/dist/{index-uE3S3Krx.d.mts → index-Bo6pkkVO.d.mts} +5 -5
- package/dist/{index-uE3S3Krx.d.mts.map → index-Bo6pkkVO.d.mts.map} +1 -1
- package/dist/{index-D8rDE60Y.d.mts → index-BsCrdweM.d.mts} +1 -1
- package/dist/index-BsCrdweM.d.mts.map +1 -0
- package/dist/{index-D7mFNjot.d.mts → index-BtPFPfja.d.mts} +1 -1
- package/dist/{index-D7mFNjot.d.mts.map → index-BtPFPfja.d.mts.map} +1 -1
- package/dist/{index-BA0EsFxS.d.mts → index-C7uSldLA.d.mts} +3 -3
- package/dist/{index-BA0EsFxS.d.mts.map → index-C7uSldLA.d.mts.map} +1 -1
- package/dist/{index-CVmgBpDt.d.mts → index-CBtUJ94I.d.mts} +3 -3
- package/dist/{index-CVmgBpDt.d.mts.map → index-CBtUJ94I.d.mts.map} +1 -1
- package/dist/{index-BD-els5J.d.mts → index-CIEdspey.d.mts} +83 -59
- package/dist/index-CIEdspey.d.mts.map +1 -0
- package/dist/{index-dCRymj_g.d.mts → index-CXz5Z5MP.d.mts} +5 -5
- package/dist/{index-dCRymj_g.d.mts.map → index-CXz5Z5MP.d.mts.map} +1 -1
- package/dist/{index-D8gcYvR9.d.mts → index-DDdSA1Rs.d.mts} +5 -5
- package/dist/{index-D8gcYvR9.d.mts.map → index-DDdSA1Rs.d.mts.map} +1 -1
- package/dist/{index-BqJ1GWAF.d.mts → index-D_JbOTtg.d.mts} +2 -2
- package/dist/index-D_JbOTtg.d.mts.map +1 -0
- package/dist/index-DzGXoCV1.d.mts +433 -0
- package/dist/index-DzGXoCV1.d.mts.map +1 -0
- package/dist/{index-CNTYbcY9.d.mts → index-Pma2THAy.d.mts} +10 -3
- package/dist/index-Pma2THAy.d.mts.map +1 -0
- package/dist/{index-CIvNgjsx.d.mts → index-hrn4s4Vn.d.mts} +2 -2
- package/dist/{index-CIvNgjsx.d.mts.map → index-hrn4s4Vn.d.mts.map} +1 -1
- package/dist/{index-D6pjHqlK.d.mts → index-lYxaV6H7.d.mts} +49 -70
- package/dist/index-lYxaV6H7.d.mts.map +1 -0
- package/dist/index-xY9km50k.d.mts +59 -0
- package/dist/index-xY9km50k.d.mts.map +1 -0
- package/dist/index.d.mts +24 -21
- package/dist/index.mjs +1 -1
- package/dist/layer/index.d.mts +1 -1
- package/dist/layer/index.mjs +1 -1
- package/dist/layer-BmrPWBkT.mjs +2 -0
- package/dist/layer-BmrPWBkT.mjs.map +1 -0
- package/dist/{layer.types-BB0MrvLg.d.mts → layer.types-smjitsoN.d.mts} +4 -4
- package/dist/{layer.types-BB0MrvLg.d.mts.map → layer.types-smjitsoN.d.mts.map} +1 -1
- package/dist/log/index.d.mts +2 -0
- package/dist/log/index.mjs +1 -0
- package/dist/log-Bh8G5umo.mjs +2 -0
- package/dist/log-Bh8G5umo.mjs.map +1 -0
- package/dist/multithread/index.d.mts +1 -1
- package/dist/multithread/index.mjs +1 -1
- package/dist/multithread-CovZ2ioL.mjs +21 -0
- package/dist/multithread-CovZ2ioL.mjs.map +1 -0
- package/dist/option/index.d.mts +1 -1
- package/dist/option/index.mjs +1 -1
- package/dist/{option-C2iCxAuJ.mjs → option-BlyP5LA2.mjs} +2 -2
- package/dist/{option-C2iCxAuJ.mjs.map → option-BlyP5LA2.mjs.map} +1 -1
- package/dist/{option.types-D9hrKcfa.d.mts → option.types-Po1qwxiW.d.mts} +3 -3
- package/dist/{option.types-D9hrKcfa.d.mts.map → option.types-Po1qwxiW.d.mts.map} +1 -1
- package/dist/{option.types-CbY_swma.mjs → option.types-bFFSErJ-.mjs} +1 -1
- package/dist/{option.types-CbY_swma.mjs.map → option.types-bFFSErJ-.mjs.map} +1 -1
- package/dist/order/index.d.mts +1 -1
- package/dist/order/index.mjs +1 -1
- package/dist/{order-BXOBEKvB.mjs → order-VTXpppmI.mjs} +2 -2
- package/dist/{order-BXOBEKvB.mjs.map → order-VTXpppmI.mjs.map} +1 -1
- package/dist/{pipeable-BIrevC0D.d.mts → pipeable-BY9yPsNK.d.mts} +1 -1
- package/dist/{pipeable-BIrevC0D.d.mts.map → pipeable-BY9yPsNK.d.mts.map} +1 -1
- package/dist/pipeable-COGyGMUV.mjs +2 -0
- package/dist/{pipeable-Dp1_23zH.mjs.map → pipeable-COGyGMUV.mjs.map} +1 -1
- package/dist/predicate/index.d.mts +1 -1
- package/dist/predicate/index.mjs +1 -1
- package/dist/predicate-CvH7cY_J.mjs +2 -0
- package/dist/predicate-CvH7cY_J.mjs.map +1 -0
- package/dist/provide/index.d.mts +1 -1
- package/dist/provide/index.mjs +1 -1
- package/dist/provide-K-6oXtLm.mjs +2 -0
- package/dist/provide-K-6oXtLm.mjs.map +1 -0
- package/dist/queue/index.d.mts +1 -1
- package/dist/queue/index.mjs +1 -1
- package/dist/{queue-GYVrD39q.mjs → queue-CeEIUHcY.mjs} +2 -2
- package/dist/{queue-GYVrD39q.mjs.map → queue-CeEIUHcY.mjs.map} +1 -1
- package/dist/{queue.types-B-l5XYbU.d.mts → queue.types-Bj63N2ab.d.mts} +1 -1
- package/dist/{queue.types-B-l5XYbU.d.mts.map → queue.types-Bj63N2ab.d.mts.map} +1 -1
- package/dist/result/index.d.mts +1 -1
- package/dist/result/index.mjs +1 -1
- package/dist/{result-D3VY0qBG.mjs → result-C74pRN2x.mjs} +2 -2
- package/dist/{result-D3VY0qBG.mjs.map → result-C74pRN2x.mjs.map} +1 -1
- package/dist/{result.types-BKzChyWY.d.mts → result.types-JEcowzYH.d.mts} +6 -27
- package/dist/result.types-JEcowzYH.d.mts.map +1 -0
- package/dist/schedule/index.d.mts +1 -1
- package/dist/schedule/index.mjs +1 -1
- package/dist/{schedule-B7qV60tO.mjs → schedule-ChcIgvd5.mjs} +2 -2
- package/dist/{schedule-B7qV60tO.mjs.map → schedule-ChcIgvd5.mjs.map} +1 -1
- package/dist/{schedule-BzPjvMXc.d.mts → schedule-ap6y014J.d.mts} +3 -3
- package/dist/{schedule-BzPjvMXc.d.mts.map → schedule-ap6y014J.d.mts.map} +1 -1
- package/dist/schema/index.d.mts +1 -1
- package/dist/schema/index.mjs +1 -1
- package/dist/schema-CjON86AZ.mjs +2 -0
- package/dist/schema-CjON86AZ.mjs.map +1 -0
- package/dist/scope/index.d.mts +1 -1
- package/dist/scope/index.mjs +1 -1
- package/dist/{scope-CuM3CzwG.d.mts → scope-BQEFiS_2.d.mts} +4 -4
- package/dist/scope-BQEFiS_2.d.mts.map +1 -0
- package/dist/scope-D2AqJy7j.mjs +2 -0
- package/dist/scope-D2AqJy7j.mjs.map +1 -0
- package/dist/service/index.d.mts +1 -1
- package/dist/service/index.mjs +1 -1
- package/dist/{service-CWAIEH46.mjs → service-DHkeorS3.mjs} +2 -2
- package/dist/{service-CWAIEH46.mjs.map → service-DHkeorS3.mjs.map} +1 -1
- package/dist/{service-D8mr0wwg.d.mts → service-DIKUYHda.d.mts} +2 -2
- package/dist/{service-D8mr0wwg.d.mts.map → service-DIKUYHda.d.mts.map} +1 -1
- package/dist/trace/index.d.mts +2 -0
- package/dist/trace/index.mjs +1 -0
- package/dist/trace-ByjppUes.mjs +2 -0
- package/dist/trace-ByjppUes.mjs.map +1 -0
- package/dist/trace-NETIRDfA.d.mts +375 -0
- package/dist/trace-NETIRDfA.d.mts.map +1 -0
- package/dist/type-utils.types-CnPpsvt5.d.mts +30 -0
- package/dist/type-utils.types-CnPpsvt5.d.mts.map +1 -0
- package/package.json +15 -5
- package/dist/adt/index.d.mts +0 -2
- package/dist/adt/index.mjs +0 -1
- package/dist/adt-CY8wLJJI.mjs +0 -2
- package/dist/adt-CY8wLJJI.mjs.map +0 -1
- package/dist/data-DqACNS_g.mjs +0 -2
- package/dist/data-DqACNS_g.mjs.map +0 -1
- package/dist/discriminator.types-C-ygT2S1.d.mts +0 -7
- package/dist/discriminator.types-C-ygT2S1.d.mts.map +0 -1
- package/dist/functions-ByAk682_.mjs +0 -2
- package/dist/fx-C_RTDEpv.mjs +0 -2
- package/dist/fx-C_RTDEpv.mjs.map +0 -1
- package/dist/fx.runtime-jQxh77s3.mjs +0 -2
- package/dist/fx.runtime-jQxh77s3.mjs.map +0 -1
- package/dist/index-BD-els5J.d.mts.map +0 -1
- package/dist/index-BaRJVkLo.d.mts +0 -458
- package/dist/index-BaRJVkLo.d.mts.map +0 -1
- package/dist/index-BipW0MC3.d.mts +0 -64
- package/dist/index-BipW0MC3.d.mts.map +0 -1
- package/dist/index-BqJ1GWAF.d.mts.map +0 -1
- package/dist/index-CNTYbcY9.d.mts.map +0 -1
- package/dist/index-D6pjHqlK.d.mts.map +0 -1
- package/dist/index-D8rDE60Y.d.mts.map +0 -1
- package/dist/index-DR7hzXU4.d.mts.map +0 -1
- package/dist/is-plain-object-BoFjRafL.mjs +0 -2
- package/dist/is-plain-object-BoFjRafL.mjs.map +0 -1
- package/dist/layer-C5A-EM0h.mjs +0 -2
- package/dist/layer-C5A-EM0h.mjs.map +0 -1
- package/dist/multithread-Cyc8Bz45.mjs +0 -19
- package/dist/multithread-Cyc8Bz45.mjs.map +0 -1
- package/dist/pipeable-Dp1_23zH.mjs +0 -2
- package/dist/predicate-D_1SsIi4.mjs +0 -2
- package/dist/predicate-D_1SsIi4.mjs.map +0 -1
- package/dist/provide-CuccogWx.mjs +0 -2
- package/dist/provide-CuccogWx.mjs.map +0 -1
- package/dist/result.types-BKzChyWY.d.mts.map +0 -1
- package/dist/schema-DstB1_VK.mjs +0 -2
- package/dist/schema-DstB1_VK.mjs.map +0 -1
- package/dist/schema.shared-Bjyroa6b.mjs +0 -2
- package/dist/schema.shared-Bjyroa6b.mjs.map +0 -1
- package/dist/schema.types-w1WK4kGS.d.mts +0 -62
- package/dist/schema.types-w1WK4kGS.d.mts.map +0 -1
- package/dist/scope-CuM3CzwG.d.mts.map +0 -1
- package/dist/scope-gVt4PESc.mjs +0 -2
- package/dist/scope-gVt4PESc.mjs.map +0 -1
- package/dist/service-resolution-BefYr4nR.mjs +0 -2
- package/dist/service-resolution-BefYr4nR.mjs.map +0 -1
- /package/dist/{chunk-oQKkju2G.mjs → chunk-6rpU2rUb.mjs} +0 -0
- /package/dist/{option-CXXiA1w-.mjs → option-BqAUkJ8e.mjs} +0 -0
- /package/dist/{result-xFLfwriM.mjs → result-B5WbPg8C.mjs} +0 -0
package/dist/fx-C_RTDEpv.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fx-C_RTDEpv.mjs","names":["gen","result","makeQueue","gen","result","resultOk","resultErr","resultTry","optionFromNullable"],"sources":["../src/fx/foreach.ts","../src/fx/fx.ts"],"sourcesContent":["import { NoSuchElementError } from \"../option/option.types\"\nimport { make as makeQueue, QueueAbortedError, QueueClosedError, QueueTaskAbortedError } from \"../queue/queue\"\nimport type { Concurrency } from \"../queue/queue.types\"\nimport { asServiceRequest } from \"../service/service-resolution\"\nimport { dual } from \"../shared/dual\"\nimport { FxTypeId } from \"./fx.types\"\nimport type { AsyncFx, FxError, FxRequirements, FxValue, FxYield, RunnableFx } from \"./fx.types\"\n\n/* oxlint-disable no-await-in-loop -- Fx.forEach coordinates child iterators and queue scheduling sequentially at specific yield points. */\n\ntype ForEachValue<Discard extends boolean, B> = Discard extends true ? void : Array<B>\n\ntype FxForEachOptions<Discard extends boolean = false> = {\n readonly concurrency?: Concurrency\n readonly discard?: Discard\n}\n\ntype ForEachFx<\n F extends (a: never, i: number) => RunnableFx<unknown, unknown, unknown>,\n Discard extends boolean,\n> = AsyncFx<ForEachValue<Discard, FxValue<ReturnType<F>>>, FxError<ReturnType<F>>, FxRequirements<ReturnType<F>>>\n\ntype FxForEach = {\n <A, F extends (a: A, i: number) => RunnableFx<unknown, unknown, unknown>, const Discard extends boolean = false>(\n self: Iterable<A>,\n f: F,\n options?: FxForEachOptions<Discard>,\n ): ForEachFx<F, Discard>\n <A, F extends (a: A, i: number) => RunnableFx<unknown, unknown, unknown>, const Discard extends boolean = false>(\n f: F,\n options?: FxForEachOptions<Discard>,\n ): (self: Iterable<A>) => ForEachFx<F, Discard>\n}\n\ntype ServiceRequestEntry<E, R> = {\n readonly yielded: FxYield<E, R>\n readonly signal: AbortSignal\n readonly resolve: (value: unknown) => void\n readonly reject: (reason: Error) => void\n}\n\ntype ResultErrShape = {\n readonly _tag: \"Err\"\n readonly error: unknown\n}\n\nclass TypedFailure<E> extends Error {\n readonly _tag = \"TypedFailure\"\n\n constructor(readonly error: E) {\n super(\"TypedFailure\")\n this.name = \"TypedFailure\"\n }\n}\n\nconst isTypedFailure = <E>(value: unknown): value is TypedFailure<E> => value instanceof TypedFailure\n\nconst isResultErr = (value: unknown): value is ResultErrShape =>\n typeof value === \"object\" && value !== null && \"_tag\" in value && value._tag === \"Err\" && \"error\" in value\n\nconst toFailureValue = (yielded: unknown): unknown => {\n if (yielded instanceof NoSuchElementError) {\n return yielded\n }\n\n if (isResultErr(yielded)) {\n return yielded.error\n }\n\n return yielded\n}\n\nconst isIterable = (value: unknown): value is Iterable<unknown> =>\n value !== null &&\n value !== undefined &&\n typeof (value as { [Symbol.iterator]?: unknown })[Symbol.iterator] === \"function\"\n\nconst queueTaskAbortedError = (signal: AbortSignal): QueueTaskAbortedError =>\n new QueueTaskAbortedError({ reason: signal.reason })\n\nconst toError = (reason: unknown): Error =>\n reason instanceof Error ? reason : new Error(\"Fx.forEach defect was not an Error\", { cause: reason })\n\nconst unreachableType = (): never => {\n throw new Error(\"Unreachable: Fx type marker should never execute at runtime\")\n}\n\nconst typeMarker = <A>(): (() => A) => unreachableType\n\nconst runMappedFx = async <B, E, R>(\n fx: RunnableFx<B, E, R>,\n signal: AbortSignal,\n requestService: (yielded: FxYield<E, R>, signal: AbortSignal) => Promise<unknown>,\n): Promise<B> => {\n if (fx._tag === \"AsyncFx\") {\n const gen = fx[Symbol.asyncIterator]()\n let result = await gen.next()\n\n while (result.done !== true) {\n if (signal.aborted) {\n throw queueTaskAbortedError(signal)\n }\n\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = await requestService(yielded, signal)\n result = await gen.next(injected)\n continue\n }\n\n // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- failure channel values come from generic E at runtime.\n throw new TypedFailure<E>(toFailureValue(yielded) as E)\n }\n\n return result.value\n }\n\n const gen = fx[Symbol.iterator]()\n let result = gen.next()\n\n while (result.done !== true) {\n if (signal.aborted) {\n throw queueTaskAbortedError(signal)\n }\n\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = await requestService(yielded, signal)\n result = gen.next(injected)\n continue\n }\n\n // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- failure channel values come from generic E at runtime.\n throw new TypedFailure<E>(toFailureValue(yielded) as E)\n }\n\n return result.value\n}\n\nconst fxForEach = dual(\n (args) => isIterable(args[0]) && typeof args[1] === \"function\",\n <A, B, E, R>(\n self: Iterable<A>,\n f: (a: A, i: number) => RunnableFx<B, E, R>,\n options?: FxForEachOptions<boolean>,\n ): AsyncFx<Array<B> | void, E, R> => {\n const items = [...self]\n const discard = options?.discard === true\n\n const program: AsyncFx<Array<B> | void, E, R> = {\n _tag: \"AsyncFx\",\n [FxTypeId]: {\n _A: typeMarker<Array<B> | void>(),\n _E: typeMarker<E>(),\n _R: typeMarker<R>(),\n },\n async *[Symbol.asyncIterator](): AsyncGenerator<FxYield<E, R>, Array<B> | void, unknown> {\n if (items.length === 0) {\n return discard ? undefined : []\n }\n\n const queue = makeQueue({ concurrency: options?.concurrency ?? \"unbounded\" })\n const results: Array<B> | undefined = discard ? undefined : []\n\n let remaining = items.length\n let firstFailure: E | undefined\n let firstDefect: Error | undefined\n let queueAborted = false\n\n const serviceRequests: ServiceRequestEntry<E, R>[] = []\n const eventWaiters = new Set<() => void>()\n\n const notifyEvent = () => {\n for (const resolve of eventWaiters) {\n resolve()\n }\n eventWaiters.clear()\n }\n\n const waitForEvent = () =>\n new Promise<void>((resolve) => {\n eventWaiters.add(resolve)\n })\n\n const requestService = (yielded: FxYield<E, R>, signal: AbortSignal): Promise<unknown> => {\n if (signal.aborted) {\n return Promise.reject(queueTaskAbortedError(signal))\n }\n\n return new Promise<unknown>((resolve, reject) => {\n const entry: ServiceRequestEntry<E, R> = {\n yielded,\n signal,\n resolve: (value) => {\n signal.removeEventListener(\"abort\", onAbort)\n resolve(value)\n },\n reject: (reason) => {\n signal.removeEventListener(\"abort\", onAbort)\n reject(reason)\n },\n }\n\n const onAbort = () => {\n const index = serviceRequests.indexOf(entry)\n if (index !== -1) {\n serviceRequests.splice(index, 1)\n }\n reject(queueTaskAbortedError(signal))\n }\n\n signal.addEventListener(\"abort\", onAbort, { once: true })\n serviceRequests.push(entry)\n notifyEvent()\n })\n }\n\n const rejectPendingServiceRequests = (reason: Error) => {\n const pending = serviceRequests.splice(0)\n for (const request of pending) {\n request.reject(reason)\n }\n }\n\n const abortQueue = (reason: unknown) => {\n if (queueAborted) {\n return\n }\n\n queueAborted = true\n void queue.shutdown({ mode: \"abort\", reason }).catch(() => {\n // no-op: fail-fast cleanup should never interrupt parent error handling\n })\n }\n\n const onTaskFailure = (error: unknown) => {\n if (isTypedFailure<E>(error)) {\n if (firstFailure === undefined && firstDefect === undefined) {\n firstFailure = error.error\n abortQueue(error.error)\n }\n return\n }\n\n if (\n (error instanceof QueueAbortedError ||\n error instanceof QueueTaskAbortedError ||\n error instanceof QueueClosedError) &&\n (firstFailure !== undefined || firstDefect !== undefined)\n ) {\n return\n }\n\n if (firstDefect === undefined && firstFailure === undefined) {\n const defect = toError(error)\n firstDefect = defect\n abortQueue(defect)\n }\n }\n\n const onTaskSettled = () => {\n remaining -= 1\n notifyEvent()\n }\n\n for (const [index, item] of items.entries()) {\n void queue\n .enqueue(async ({ signal }) => {\n const value = await runMappedFx(f(item, index), signal, requestService)\n if (results !== undefined) {\n results[index] = value\n }\n })\n .catch(onTaskFailure)\n .finally(onTaskSettled)\n }\n\n while (true) {\n if (firstDefect !== undefined) {\n rejectPendingServiceRequests(firstDefect)\n throw new Error(\"Fx.forEach defect\", { cause: firstDefect })\n }\n\n if (firstFailure !== undefined) {\n rejectPendingServiceRequests(new QueueAbortedError({ reason: firstFailure }))\n yield firstFailure\n throw new Error(\"Unreachable: Fx runtime short-circuits on first failure\")\n }\n\n const request = serviceRequests.shift()\n if (request !== undefined) {\n if (request.signal.aborted) {\n request.reject(queueTaskAbortedError(request.signal))\n continue\n }\n\n try {\n const injected = yield request.yielded\n request.resolve(injected)\n } catch (error) {\n request.reject(toError(error))\n }\n continue\n }\n\n if (remaining === 0) {\n break\n }\n\n await waitForEvent()\n }\n\n return discard ? undefined : results\n },\n }\n\n return program\n },\n) as FxForEach\n\nexport { fxForEach as forEach }\n\n/* oxlint-enable no-await-in-loop */\n","/**\n * Lightweight effect runtime with typed success, error, and requirement channels.\n *\n * **Mental model**\n * - `Fx<A, E, R>` models computations that may fail and require services.\n * - Build with `Fx.gen`, run with `Fx.run`, and compose with `Layer`/`Provide`.\n *\n * **Common tasks**\n * - Create workflows with `Fx.gen`.\n * - Execute with `Fx.run` or `Fx.fn`.\n * - Retry with `Fx.retry` and match outcomes with `Fx.match`.\n *\n * **Gotchas**\n * - Dependencies (`R`) must be provided before execution.\n * - `Fx.run` returns `Exit`, not raw values.\n *\n * **Quickstart**\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const program = Fx.gen(function* () {\n * const value = yield* Fx.ok(2)\n * return value + 1\n * })\n * const exit = Fx.run(program)\n * // => { _tag: \"Ok\", value: 3 }\n * ```\n *\n * @module\n */\nimport { fromNullable as optionFromNullable } from \"../option/option\"\nimport { ok as resultOk, err as resultErr, fromTry as resultTry } from \"../result/result\"\nimport type { RetrySchedule, SyncRetrySchedule } from \"../schedule/schedule\"\nimport { asServiceRequest } from \"../service/service-resolution\"\nimport { dual } from \"../shared/dual\"\nimport type { Exit as ExitType } from \"./exit\"\nimport { forEach as fxForEach } from \"./foreach\"\nimport { runSync, runAsync } from \"./fx.runtime\"\nimport { FxTypeId } from \"./fx.types\"\nimport type { RunnableFx, SyncFx, AsyncFx, FxYield, Fx as FxProtocol, FxGenerator, AsyncFxGenerator } from \"./fx.types\"\nexport {\n /**\n * `Exit` utilities namespace for `Fx.run` outcomes.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = Fx.Exit.ok(1)\n * // => { _tag: \"Ok\", value: 1 }\n * ```\n *\n */\n Exit,\n} from \"./exit\"\nexport {\n /**\n * Type guard for Fx service requests.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const request = { _tag: \"ServiceRequest\", serviceKey: \"Logger\" } as Fx.ServiceRequest<unknown>\n * const isRequest = Fx.isServiceRequest(request)\n * // => true\n * ```\n *\n */\n isServiceRequest,\n} from \"./fx.types\"\nexport {\n /**\n * Runtime unique symbol identifying Fx values.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const marker = { [Fx.FxTypeId]: true }\n * // => Object.getOwnPropertySymbols(marker).includes(Fx.FxTypeId)\n * ```\n *\n */\n FxTypeId,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported core Fx protocol type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.Fx<unknown, unknown, unknown>\n * ```\n *\n */\n type Fx,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported synchronous Fx type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.SyncFx<unknown, unknown, unknown>\n * ```\n *\n */\n type SyncFx,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported asynchronous Fx type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.AsyncFx<unknown, unknown, unknown>\n * ```\n *\n */\n type AsyncFx,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported runnable Fx union type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.RunnableFx<unknown, unknown, unknown>\n * ```\n *\n */\n type RunnableFx,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported service-request protocol type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.ServiceRequest<unknown>\n * ```\n *\n */\n type ServiceRequest,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported helper extracting Fx success type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxValue<Fx.SyncFx<number>>\n * ```\n *\n */\n type FxValue,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported helper extracting Fx error type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxError<Fx.SyncFx<number, string>>\n * ```\n *\n */\n type FxError,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported helper extracting Fx requirements type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxRequirements<Fx.SyncFx<number, never, { readonly svc: unknown }>>\n * ```\n *\n */\n type FxRequirements,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported generator yield union for Fx internals.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxYield<unknown, unknown>\n * ```\n *\n */\n type FxYield,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported sync generator signature used by `Fx.gen`.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxGenerator<unknown, unknown, unknown>\n * ```\n *\n */\n type FxGenerator,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported async generator signature used by `Fx.gen`.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.AsyncFxGenerator<unknown, unknown, unknown>\n * ```\n *\n */\n type AsyncFxGenerator,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported sync Fx yieldable protocol type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxYieldable<unknown, unknown, unknown>\n * ```\n *\n */\n type FxYieldable,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported async Fx yieldable protocol type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.AsyncFxYieldable<unknown, unknown, unknown>\n * ```\n *\n */\n type AsyncFxYieldable,\n} from \"./fx.types\"\n\n/* oxlint-disable no-unsafe-type-assertion, no-unsafe-assignment, no-unsafe-call, no-unsafe-member-access, no-unsafe-return, no-unsafe-argument, no-unnecessary-type-assertion -- Fx runtime adapters intentionally traverse erased generator channels and rehydrate typed effects through controlled dynamic boundaries. */\n\n// ============================================================================\n// Fx.run - Execute computations\n// ============================================================================\n\n/**\n * Execute a sync Fx computation and return the Exit.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * Only available when R = never (all dependencies provided).\n *\n * @param fx - The sync computation to execute\n * @returns Exit<A, E>\n */\nfunction fxRun<A, E>(fx: SyncFx<A, E>): ExitType<A, E>\n\n/**\n * Execute an async Fx computation and return a Promise of the Exit.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * Only available when R = never (all dependencies provided).\n *\n * @param fx - The async computation to execute\n * @returns Promise<Exit<A, E>>\n */\nfunction fxRun<A, E>(fx: AsyncFx<A, E>): Promise<ExitType<A, E>>\n\n/**\n * Execute an Fx computation (union type).\n * Returns Exit for sync, Promise<Exit> for async.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n */\nfunction fxRun<A, E>(fx: RunnableFx<A, E>): ExitType<A, E> | Promise<ExitType<A, E>>\n\n/**\n * Implementation of Fx.run.\n * Detects sync vs async and executes appropriately.\n */\nfunction fxRun<A, E>(fx: RunnableFx<A, E>): ExitType<A, E> | Promise<ExitType<A, E>> {\n if (fx._tag === \"AsyncFx\") {\n return runAsync(fx)\n }\n return runSync(fx)\n}\n\n// ============================================================================\n// Fx.retry - Retry failed computations\n// ============================================================================\n\nconst sleep = (ms: number): Promise<void> =>\n new Promise((resolve) => {\n setTimeout(resolve, ms)\n })\n\nconst sleepIfNeeded = async (ms: number): Promise<void> => {\n if (ms <= 0) {\n return\n }\n await sleep(ms)\n}\n\nconst closeSyncAttempt = (gen: Generator<unknown, unknown, unknown>) => {\n if (typeof gen.return === \"function\") {\n gen.return(undefined)\n }\n}\n\nconst closeAsyncAttempt = async (\n gen: Generator<unknown, unknown, unknown> | AsyncGenerator<unknown, unknown, unknown>,\n) => {\n if (typeof gen.return === \"function\") {\n await gen.return(undefined)\n }\n}\n\nconst makeSyncRetryFx = <A, E, R>(fx: SyncFx<A, E, R>, schedule: SyncRetrySchedule): SyncFx<A, E, R> => ({\n _tag: \"SyncFx\",\n [FxTypeId]: {\n _A: () => undefined as unknown as A,\n _E: () => undefined as unknown as E,\n _R: () => undefined as unknown as R,\n },\n *[Symbol.iterator](): Generator<FxYield<E, R>, A, unknown> {\n let retryAttempt = 0\n attemptLoop: while (true) {\n const gen = fx[Symbol.iterator]()\n let result = gen.next()\n\n while (result.done !== true) {\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = yield yielded as FxYield<E, R>\n result = gen.next(injected)\n continue\n }\n\n retryAttempt += 1\n if (retryAttempt <= schedule.maxRetries) {\n closeSyncAttempt(gen)\n continue attemptLoop\n }\n\n // Forward the terminal typed failure to the outer runtime.\n yield yielded as FxYield<E, R>\n return undefined as never\n }\n\n return result.value\n }\n },\n})\n\n/* oxlint-disable no-await-in-loop -- retry execution is intentionally sequential across attempts and iterator steps. */\nconst makeAsyncRetryFx = <A, E, R>(fx: RunnableFx<A, E, R>, schedule: RetrySchedule): AsyncFx<A, E, R> => ({\n _tag: \"AsyncFx\",\n [FxTypeId]: {\n _A: () => undefined as unknown as A,\n _E: () => undefined as unknown as E,\n _R: () => undefined as unknown as R,\n },\n async *[Symbol.asyncIterator](): AsyncGenerator<FxYield<E, R>, A, unknown> {\n let retryAttempt = 0\n\n attemptLoop: while (true) {\n if (fx._tag === \"AsyncFx\") {\n const gen = fx[Symbol.asyncIterator]()\n // Sequential async iterator protocol: each step depends on the previous one.\n let result = await gen.next()\n\n while (result.done !== true) {\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = yield yielded as FxYield<E, R>\n // oxlint-disable-next-line no-await-in-loop\n result = await gen.next(injected)\n continue\n }\n\n retryAttempt += 1\n if (retryAttempt <= schedule.maxRetries) {\n const delayMs = schedule.delayForAttempt(retryAttempt)\n await sleepIfNeeded(delayMs)\n await closeAsyncAttempt(gen)\n continue attemptLoop\n }\n\n // Forward the terminal typed failure to the outer runtime.\n yield yielded as FxYield<E, R>\n return undefined as never\n }\n\n return result.value\n }\n\n const gen = fx[Symbol.iterator]()\n let result = gen.next()\n\n while (result.done !== true) {\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = yield yielded as FxYield<E, R>\n result = gen.next(injected)\n continue\n }\n\n retryAttempt += 1\n if (retryAttempt <= schedule.maxRetries) {\n const delayMs = schedule.delayForAttempt(retryAttempt)\n await sleepIfNeeded(delayMs)\n await closeAsyncAttempt(gen)\n continue attemptLoop\n }\n\n // Forward the terminal typed failure to the outer runtime.\n yield yielded as FxYield<E, R>\n return undefined as never\n }\n\n return result.value\n }\n },\n})\n/* oxlint-enable no-await-in-loop */\n\n/**\n * Retry a computation according to the given schedule.\n *\n * Retries only typed failures (Err channel). Defects are not retried.\n */\ntype RetryResult<Fx extends RunnableFx<unknown, unknown, unknown>, S extends RetrySchedule> =\n Fx extends AsyncFx<infer A, infer E, infer R>\n ? AsyncFx<A, E, R>\n : S extends SyncRetrySchedule\n ? Fx extends SyncFx<infer A, infer E, infer R>\n ? SyncFx<A, E, R>\n : never\n : Fx extends SyncFx<infer A, infer E, infer R>\n ? AsyncFx<A, E, R>\n : never\n\nconst fxRetry: {\n <Fx extends RunnableFx<unknown, unknown, unknown>, S extends RetrySchedule>(fx: Fx, schedule: S): RetryResult<Fx, S>\n <S extends RetrySchedule>(\n schedule: S,\n ): <Fx extends RunnableFx<unknown, unknown, unknown>>(fx: Fx) => RetryResult<Fx, S>\n} = dual(\n 2,\n <Fx extends RunnableFx<unknown, unknown, unknown>, S extends RetrySchedule>(\n fx: Fx,\n schedule: S,\n ): RetryResult<Fx, S> => {\n if (fx._tag === \"AsyncFx\" || !schedule._sync) {\n return makeAsyncRetryFx(fx, schedule) as RetryResult<Fx, S>\n }\n return makeSyncRetryFx(fx as SyncFx<unknown, unknown, unknown>, schedule as SyncRetrySchedule) as RetryResult<Fx, S>\n },\n)\n\n// ============================================================================\n// Fx.gen - Create composable computations\n// ============================================================================\n\ntype FxGenError<Yielded> = Yielded extends FxProtocol<unknown, infer E, unknown> ? E : Yielded\ntype FxGenRequirements<Yielded> = Yielded extends FxProtocol<unknown, unknown, infer R> ? R : never\n\n/**\n * Create a composable computation from a sync generator function.\n * Returns a SyncFx that can be stored, passed around, and executed later.\n *\n * @template Yielded - The type of values yielded by the generator\n * @template A - The success value type\n * @param generatorFn - A function that returns a sync generator\n * @returns SyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Port = Service.tag<number>(\"Port\")\n * const readPort = Fx.gen(function* () {\n * return yield* Port\n * })\n * const exit = Fx.run(Provide.service(Port, 3000)(readPort))\n * // => { _tag: \"Ok\", value: 3000 }\n * ```\n */\nfunction fxGen<Yielded, A>(\n generatorFn: () => Generator<Yielded, A, unknown>,\n): SyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n\n/**\n * Create a composable computation from an async generator function.\n * Returns an AsyncFx that can be stored, passed around, and executed later.\n *\n * @template Yielded - The type of values yielded by the generator\n * @template A - The success value type\n * @param generatorFn - A function that returns an async generator\n * @returns AsyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Token = Service.tag<string>(\"Token\")\n * const readToken = Fx.gen(async function* () {\n * const token = yield* Token\n * const suffix = await Promise.resolve(\"-ok\")\n * return `${token}${suffix}`\n * })\n * const exit = await Fx.run(Provide.service(Token, \"abc\")(readToken))\n * // => { _tag: \"Ok\", value: \"abc-ok\" }\n * ```\n */\nfunction fxGen<Yielded, A>(\n generatorFn: () => AsyncGenerator<Yielded, A, unknown>,\n): AsyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n\n/**\n * Create a composable computation from a sync generator function that takes parameters.\n * Returns a factory function that, when called with parameters, produces a SyncFx.\n *\n * @template P - The parameter types (must be non-empty)\n * @template Yielded - The type of values yielded by the generator\n * @template A - The success value type\n * @param generatorFn - A function that takes parameters and returns a sync generator\n * @returns A factory function that produces SyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Port = Service.tag<number>(\"Port\")\n * const describePort = Fx.gen(function* (label: string) {\n * const port = yield* Port\n * return `${label}:${port}`\n * })\n * const exit = Fx.run(Provide.service(Port, 3000)(describePort(\"port\")))\n * // => { _tag: \"Ok\", value: \"port:3000\" }\n * ```\n */\nfunction fxGen<P extends [unknown, ...unknown[]], Yielded, A>(\n generatorFn: (...params: P) => Generator<Yielded, A, unknown>,\n): (...params: P) => SyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n\n/**\n * Create a composable computation from an async generator function that takes parameters.\n * Returns a factory function that, when called with parameters, produces an AsyncFx.\n *\n * @template P - The parameter types (must be non-empty)\n * @template Yielded - The type of values yielded by the generator\n * @template A - The success value type\n * @param generatorFn - A function that takes parameters and returns an async generator\n * @returns A factory function that produces AsyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Token = Service.tag<string>(\"Token\")\n * const describeToken = Fx.gen(async function* (prefix: string) {\n * const token = yield* Token\n * const suffix = await Promise.resolve(\"!\")\n * return `${prefix}:${token}${suffix}`\n * })\n * const exit = await Fx.run(Provide.service(Token, \"abc\")(describeToken(\"token\")))\n * // => { _tag: \"Ok\", value: \"token:abc!\" }\n * ```\n */\nfunction fxGen<P extends [unknown, ...unknown[]], Yielded, A>(\n generatorFn: (...params: P) => AsyncGenerator<Yielded, A, unknown>,\n): (...params: P) => AsyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n\n/**\n * Implementation of unified Fx.gen function.\n * Detects sync vs async generator and returns appropriate computation type.\n * For parameterized generators (length > 0), returns a factory function.\n */\n// oxlint-disable-next-line no-explicit-any\nfunction fxGen(generatorFn: (...args: any[]) => any): any {\n if (generatorFn.length > 0) {\n return (...params: unknown[]) => fxGen(() => generatorFn(...params))\n }\n\n // Check if we're dealing with async generator\n const testGen = generatorFn()\n const isAsync = Symbol.asyncIterator in testGen\n\n if (isAsync) {\n return {\n _tag: \"AsyncFx\",\n [FxTypeId]: {\n _A: () => undefined,\n _E: () => undefined,\n _R: () => undefined,\n },\n // oxlint-disable-next-line no-explicit-any\n async *[Symbol.asyncIterator](): AsyncGenerator<any, any, unknown> {\n const gen = generatorFn()\n let result = await gen.next()\n\n while (result.done !== true) {\n // Pass through yields (errors or services as Fx values)\n const injected = yield result.value\n // oxlint-disable-next-line no-await-in-loop\n result = await gen.next(injected)\n }\n\n return result.value\n },\n }\n }\n\n // Sync generator\n return {\n _tag: \"SyncFx\",\n [FxTypeId]: {\n _A: () => undefined,\n _E: () => undefined,\n _R: () => undefined,\n },\n // oxlint-disable-next-line no-explicit-any\n *[Symbol.iterator](): Generator<any, any, unknown> {\n const gen = generatorFn()\n let result = gen.next()\n\n while (result.done !== true) {\n const injected = yield result.value\n result = gen.next(injected)\n }\n\n return result.value\n },\n }\n}\n\n// ============================================================================\n// Fx.fn - Execute computations immediately\n// ============================================================================\n\ntype FxRunResult<F extends RunnableFx<unknown, unknown, unknown>> =\n F extends AsyncFx<infer A, infer E, unknown>\n ? Promise<ExitType<A, E>>\n : F extends SyncFx<infer A, infer E, unknown>\n ? ExitType<A, E>\n : never\n\n/**\n * Execute a sync computation immediately and return the Exit.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * For computations without service dependencies.\n *\n * @template A - The success value type\n * @template E - The error type\n * @param generatorFn - A function that returns a sync generator\n * @returns Exit<A, E>\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = Fx.fn(function* () {\n * const a = yield* Fx.ok(10)\n * const b = yield* Fx.ok(20)\n * return a + b\n * })\n * // => { _tag: \"Ok\", value: 30 }\n * ```\n */\nfunction fxFn<A, E>(generatorFn: () => FxGenerator<A, E, never>): ExitType<A, E>\n\n/**\n * Execute an async computation immediately and return a Promise of the Exit.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * For computations without service dependencies.\n *\n * @template A - The success value type\n * @template E - The error type\n * @param generatorFn - A function that returns an async generator\n * @returns Promise<Exit<A, E>>\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = await Fx.fn(async function* () {\n * const value = await Promise.resolve(2)\n * return value + 1\n * })\n * // => { _tag: \"Ok\", value: 3 }\n * ```\n */\nfunction fxFn<A, E>(generatorFn: () => AsyncFxGenerator<A, E, never>): Promise<ExitType<A, E>>\n\n/**\n * Execute a sync computation with service dependencies immediately.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * The second argument is required when the computation has service requirements (R ≠ never).\n *\n * @template A - The success value type\n * @template E - The error type from the computation\n * @template R - The required services type\n * @param generatorFn - A function that returns a sync generator with service requirements\n * @param provider - A function that provides the services (e.g., Provide.layer(AppLayer))\n * @returns Exit result from running the provided Fx (sync or async depending on provider output)\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Port = Service.tag<number>(\"Port\")\n *\n * const exit = Fx.fn(function* () {\n * const port = yield* Port\n * return port + 1\n * }, Provide.service(Port, 3000))\n * // => { _tag: \"Ok\", value: 3001 }\n * ```\n */\nfunction fxFn<A, E, R, ProvidedFx extends RunnableFx<unknown, unknown, unknown>>(\n generatorFn: () => FxGenerator<A, E, R>,\n provider: (fx: SyncFx<A, E, R>) => ProvidedFx,\n): FxRunResult<ProvidedFx>\n\n/**\n * Execute an async computation with service dependencies immediately.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * The second argument is required when the computation has service requirements (R ≠ never).\n *\n * @template A - The success value type\n * @template E - The error type from the computation\n * @template R - The required services type\n * @param generatorFn - A function that returns an async generator with service requirements\n * @param provider - A function that provides the services (e.g., Provide.layer(AppLayer))\n * @returns Exit result from running the provided Fx (sync or async depending on provider output)\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Token = Service.tag<string>(\"Token\")\n *\n * const exit = await Fx.fn(async function* () {\n * const token = yield* Token\n * const suffix = await Promise.resolve(\"!\")\n * return `${token}${suffix}`\n * }, Provide.service(Token, \"abc\"))\n * // => { _tag: \"Ok\", value: \"abc!\" }\n * ```\n */\nfunction fxFn<A, E, R, ProvidedFx extends RunnableFx<unknown, unknown, unknown>>(\n generatorFn: () => AsyncFxGenerator<A, E, R>,\n provider: (fx: AsyncFx<A, E, R>) => ProvidedFx,\n): FxRunResult<ProvidedFx>\n\n/**\n * Implementation of Fx.fn.\n * Reuses fxGen() for Fx creation and fxRun() for execution to ensure consistent behavior.\n */\nfunction fxFn<A, E, E2, R>(\n generatorFn: () => FxGenerator<A, E, R> | AsyncFxGenerator<A, E, R>,\n provider?: ((fx: SyncFx<A, E, R>) => RunnableFx<A, E | E2>) | ((fx: AsyncFx<A, E, R>) => RunnableFx<A, E | E2>),\n): ExitType<A, E | E2> | Promise<ExitType<A, E | E2>> {\n // Create the Fx using fxGen (single source of truth for Fx creation)\n // Type cast needed because fxGen infers E/R from yielded Fx values,\n // while fxFn receives E/R as explicit type parameters\n // oxlint-disable-next-line no-explicit-any\n const fx = fxGen(generatorFn as any) as RunnableFx<A, E, R>\n\n if (provider) {\n // Apply provider and run\n const provided =\n fx._tag === \"AsyncFx\"\n ? (provider as (fx: AsyncFx<A, E, R>) => RunnableFx<A, E | E2>)(fx)\n : (provider as (fx: SyncFx<A, E, R>) => RunnableFx<A, E | E2>)(fx)\n return fxRun(provided as RunnableFx<A, E | E2>) as ExitType<A, E | E2> | Promise<ExitType<A, E | E2>>\n }\n\n // No provider - run directly (R must be never at the type level)\n return fxRun(fx as RunnableFx<A, E | E2>) as ExitType<A, E | E2> | Promise<ExitType<A, E | E2>>\n}\n\n// ============================================================================\n// Fx.ok / Fx.err / Fx.option - Convenience aliases\n// ============================================================================\n\n/**\n * Convenience alias for Result.ok.\n * Creates a successful Result that can be yielded in an Fx computation.\n *\n * @param value - The success value\n * @returns Result<T, never>\n *\n * @example\n * ```ts\n * const workflow = Fx.gen(function* () {\n * const value = yield* Fx.ok(42)\n * return value * 2\n * })\n * ```\n */\nconst fxOk = resultOk\n\n/**\n * Convenience alias for Result.err.\n * Creates an error Result that can be yielded in an Fx computation.\n *\n * @param error - The error value\n * @returns Result<never, E>\n *\n * @example\n * ```ts\n * const workflow = Fx.gen(function* () {\n * const config = yield* Config\n *\n * if (!config.dbUrl) {\n * return yield* Fx.err(new ValidationError({ field: \"dbUrl\" }))\n * }\n *\n * return config.dbUrl\n * })\n * ```\n */\nconst fxErr = resultErr\n\n/**\n * Convenience alias for Result.try.\n * Creates a Result that can be yielded in an Fx computation.\n *\n * @param fn - A function that returns a value or throws an error\n * @returns Result<T, E>\n *\n * @example\n * ```ts\n * const result = Fx.try(() => {\n * return 42\n * })\n *\n * const workflow = Fx.gen(function* () {\n * const result = yield* Fx.try(() => {\n * return 42\n * })\n * return result\n * })\n * ```\n */\nconst fxTry = resultTry\n\n/**\n * Convenience alias for Option.fromNullable.\n * Converts nullable values into an Option that can be yielded in an Fx computation.\n *\n * @param value - A possibly nullish value\n * @returns Option<NonNullable<T>>\n *\n * @example\n * ```ts\n * const workflow = Fx.gen(function* () {\n * const apiKey = yield* Fx.option(request.headers[\"x-api-key\"])\n * return apiKey\n * })\n * ```\n */\nconst fxOption = optionFromNullable\n\n// ============================================================================\n// Fx.match - Universal pattern matching\n// ============================================================================\n\n/**\n * Handler functions for matching on a tagged union by `_tag` discriminator.\n * Each handler receives the narrowed variant corresponding to its tag key.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = typeof Fx\n * ```\n */\nexport type TaggedMatch<T extends { readonly _tag: string }, R> = {\n readonly [K in T[\"_tag\"]]: (variant: Extract<T, { readonly _tag: K }>) => R\n}\n\n/**\n * Generic pattern matcher for any `_tag`-based discriminated union.\n *\n * Works with Exit, tagged errors, or any type with a `readonly _tag` discriminator.\n * Each handler receives the full narrowed variant object for its tag.\n *\n * Supports both data-first and data-last (pipe) calling styles.\n *\n * @example\n * ```ts\n * // Match on Exit\n * Fx.match(exit, {\n * Ok: (ok) => ok.value,\n * Err: (err) =>\n * Fx.match(err.error, {\n * DatabaseError: (e) => e.message,\n * NotFoundError: (e) => e.resourceId,\n * }),\n * Defect: (d) => String(d.defect),\n * })\n *\n * // Data-last with pipe\n * pipe(exit, Fx.match({\n * Ok: (ok) => ok.value,\n * Err: (err) => \"error\",\n * Defect: (d) => \"defect\",\n * }))\n * ```\n */\nconst fxMatch: {\n <T extends { readonly _tag: string }, R>(value: T, handlers: TaggedMatch<T, R>): R\n <T extends { readonly _tag: string }, R>(handlers: TaggedMatch<T, R>): (value: T) => R\n} = dual(\n 2,\n // oxlint-disable-next-line no-explicit-any\n (value: any, handlers: any): any => handlers[value._tag](value),\n)\n\n// ============================================================================\n// Exports\n// ============================================================================\n\n/**\n * Build typed computations from generator functions.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const program = Fx.gen(function* () {\n * const value = yield* Fx.ok(2)\n * return value + 1\n * })\n * const exit = Fx.run(program)\n * // => { _tag: \"Ok\", value: 3 }\n * ```\n */\nexport const gen = fxGen\n\n/**\n * Run a generator function immediately and return its `Exit`.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = Fx.fn(function* () {\n * return yield* Fx.ok(2)\n * })\n * // => { _tag: \"Ok\", value: 2 }\n * ```\n */\nexport const fn = fxFn\n\n/**\n * Execute an existing `Fx` value and produce an `Exit`.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = Fx.run(Fx.gen(function* () {\n * return 1\n * }))\n * // => { _tag: \"Ok\", value: 1 }\n * ```\n */\nexport const run = fxRun\n\n/**\n * Retry failed computations according to a schedule.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * import { Schedule } from \"@nicolastoulemont/std\"\n *\n * const retried = Fx.retry(\n * Fx.gen(function* () {\n * return yield* Fx.err(\"boom\")\n * }),\n * Schedule.recurs(2),\n * )\n * const exit = Fx.run(retried)\n * // => { _tag: \"Err\", error: \"boom\" }\n * ```\n */\nexport const retry = fxRetry\n\n/**\n * Run an effectful function for each item in a collection.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const fx = Fx.forEach([1, 2, 3], (n) => Fx.gen(function* () {\n * return n * 2\n * }))\n * // => AsyncFx<readonly number[], ...>\n * ```\n */\nexport const forEach = fxForEach\n\n/**\n * Alias for `Result.ok` in `Fx` namespace.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const value = Fx.ok(42)\n * // => { _tag: \"Ok\", value: 42 }\n * ```\n */\nexport const ok = fxOk\n\n/**\n * Alias for `Result.err` in `Fx` namespace.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const value = Fx.err(\"boom\")\n * // => { _tag: \"Err\", error: \"boom\" }\n * ```\n */\nexport const err = fxErr\n\n/**\n * Alias for `Option.fromNullable` in `Fx` namespace.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const value = Fx.option(\"token\")\n * // => { _tag: \"Some\", value: \"token\" }\n * ```\n */\nexport const option = fxOption\n\nconst try_ = fxTry\n\nexport {\n /**\n * Alias for `Result.fromTry` in `Fx` namespace.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const parsed = Fx.try(() => Number.parseInt(\"42\", 10))\n * // => { _tag: \"Ok\", value: 42 }\n * ```\n *\n */\n try_ as try,\n}\n\n/**\n * Pattern matching helper for tagged unions.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const value = Fx.match({ _tag: \"Ok\", value: 2 } as const, {\n * Ok: (ok) => ok.value + 1,\n * })\n * // => 3\n * ```\n */\nexport const match = fxMatch\n\n/* oxlint-enable no-unsafe-type-assertion, no-unsafe-assignment, no-unsafe-call, no-unsafe-member-access, no-unsafe-return, no-unsafe-argument, no-unnecessary-type-assertion */\n"],"mappings":"icA8CA,IAAM,EAAN,cAA8B,KAAM,CAClC,KAAgB,eAEhB,YAAY,EAAmB,CAC7B,MAAM,eAAe,CADF,KAAA,MAAA,EAEnB,KAAK,KAAO,iBAIhB,MAAM,EAAqB,GAA6C,aAAiB,EAEnF,EAAe,GACnB,OAAO,GAAU,YAAY,GAAkB,SAAU,GAAS,EAAM,OAAS,OAAS,UAAW,EAEjG,EAAkB,GAClB,aAAmB,EACd,EAGL,EAAY,EAAQ,CACf,EAAQ,MAGV,EAGH,EAAc,GAClB,GAAU,MAEV,OAAQ,EAA0C,OAAO,WAAc,WAEnE,EAAyB,GAC7B,IAAI,EAAsB,CAAE,OAAQ,EAAO,OAAQ,CAAC,CAEhD,EAAW,GACf,aAAkB,MAAQ,EAAa,MAAM,qCAAsC,CAAE,MAAO,EAAQ,CAAC,CAEjG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G7B,OAAO,EAAO,OAEjB,CA8HH,SAAS,EACP,EACA,EACoD,CAKpD,IAAM,EAAK,EAAM,EAAmB,CAYpC,OAJS,EANL,GAGA,EAAG,KACE,EAA6D,EAAG,EAM5D,EAJoC,CA0BnD,MAAM,EAAOE,EAsBP,EAAQC,EAuBR,EAAQC,EAiBR,EAAWC,EAkDX,EAGF,EACF,GAEC,EAAY,IAAuB,EAAS,EAAM,MAAM,EAAM,CAChE,CAqBY,EAAM,EAeN,EAAK,EAeL,EAAM,EAqBN,EAAQ,EAeR,EAAU,EAaV,EAAK,EAaL,EAAM,EAaN,EAAS,EAEhB,EAAO,EA+BA,EAAQ"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./dual-fN6OUwN_.mjs";import{t}from"./option.types-CbY_swma.mjs";import{t as n}from"./service-resolution-BefYr4nR.mjs";const r=e=>({_tag:`Ok`,value:e}),i=e=>({_tag:`Err`,error:e}),a=e=>({_tag:`Defect`,defect:e}),o={ok:r,err:i,defect:a,isOk:e=>e._tag===`Ok`,isErr:e=>e._tag===`Err`,isDefect:e=>e._tag===`Defect`,match:e(2,(e,t)=>{switch(e._tag){case`Ok`:return t.Ok(e.value);case`Err`:return t.Err(e.error);case`Defect`:return t.Defect(e.defect)}}),getOrThrow:e=>{switch(e._tag){case`Ok`:return e.value;case`Err`:throw e.error;case`Defect`:throw e.defect}}};function s(e){try{let o=e[Symbol.iterator]().next();if(o.done!==!0){let e=o.value,r=n(e);return r===void 0?e instanceof t?i(e):typeof e==`object`&&e&&`_tag`in e&&e._tag===`Err`?i(e.error):i(e):a(Error(`Service "${r.key}" not provided. Use Provide.layer() to inject services.`))}return r(o.value)}catch(e){return a(e)}}async function c(e){try{let o=await e[Symbol.asyncIterator]().next();if(o.done!==!0){let e=o.value,r=n(e);return r===void 0?e instanceof t?i(e):typeof e==`object`&&e&&`_tag`in e&&e._tag===`Err`?i(e.error):i(e):a(Error(`Service "${r.key}" not provided. Use Provide.layer() to inject services.`))}return r(o.value)}catch(e){return a(e)}}export{s as n,o as r,c as t};
|
|
2
|
-
//# sourceMappingURL=fx.runtime-jQxh77s3.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fx.runtime-jQxh77s3.mjs","names":["exitDefect","exitErr","exitOk"],"sources":["../src/fx/exit.ts","../src/fx/fx.runtime.ts"],"sourcesContent":["import { dual } from \"../shared/dual\"\nimport type { Err, Ok } from \"../shared/type-utils.types\"\n\n// ============================================================================\n// Exit Types - Flat 3-variant discriminated union\n// ============================================================================\n\n/**\n * Represents an unexpected thrown exception (defect) caught during Fx execution.\n */\ntype Defect = {\n readonly _tag: \"Defect\"\n readonly defect: unknown\n}\n\n/**\n * Exit represents the outcome of an Fx computation.\n * A flat 3-variant discriminated union that cleanly separates:\n * - `Ok<A>`: successful result with value of type A\n * - `Err<E>`: typed failure with error of type E\n * - `Defect`: unexpected thrown exception (defect)\n *\n * @example\n * ```ts\n * const exit = Fx.run(computation)\n * switch (exit._tag) {\n * case \"Ok\": exit.value // A\n * case \"Err\": exit.error // E (clean!)\n * case \"Defect\": exit.defect // unknown\n * }\n * ```\n */\nexport type Exit<A, E> = Ok<A> | Err<E> | Defect\n\n// ============================================================================\n// Constructors\n// ============================================================================\n\n/**\n * Create a successful Exit.\n */\nexport const ok = <A>(value: A): Ok<A> => ({ _tag: \"Ok\", value })\n\n/**\n * Create a typed failure Exit.\n */\nexport const err = <E>(error: E): Err<E> => ({ _tag: \"Err\", error })\n\n/**\n * Create a defect Exit from an unexpected thrown value.\n */\nexport const defect = (thrown: unknown): Defect => ({ _tag: \"Defect\", defect: thrown })\n\n// ============================================================================\n// Guards\n// ============================================================================\n\n/**\n * Check if an Exit is a successful result.\n */\nconst isOk = <A, E>(exit: Exit<A, E>): exit is Ok<A> => exit._tag === \"Ok\"\n\n/**\n * Check if an Exit is a typed failure.\n */\nconst isErr = <A, E>(exit: Exit<A, E>): exit is Err<E> => exit._tag === \"Err\"\n\n/**\n * Check if an Exit is an unexpected defect.\n */\nconst isDefect = <A, E>(exit: Exit<A, E>): exit is Defect => exit._tag === \"Defect\"\n\n// ============================================================================\n// Match\n// ============================================================================\n\n/**\n * Handler functions for Exit.match.\n */\ntype ExitMatch<A, E, R> = {\n readonly Ok: (value: A) => R\n readonly Err: (error: E) => R\n readonly Defect: (defect: unknown) => R\n}\n\n/**\n * Pattern match on an Exit value.\n *\n * @example\n * ```ts\n * // Data-first\n * Exit.match(exit, {\n * Ok: (value) => `Success: ${value}`,\n * Err: (error) => `Error: ${error}`,\n * Defect: (defect) => `Defect: ${defect}`,\n * })\n *\n * // Data-last (pipe)\n * pipe(exit, Exit.match({\n * Ok: (value) => `Success: ${value}`,\n * Err: (error) => `Error: ${error}`,\n * Defect: (defect) => `Defect: ${defect}`,\n * }))\n * ```\n */\nconst match: {\n <A, E, R>(exit: Exit<A, E>, handlers: ExitMatch<A, E, R>): R\n <A, E, R>(handlers: ExitMatch<A, E, R>): (exit: Exit<A, E>) => R\n} = dual(2, <A, E, R>(exit: Exit<A, E>, handlers: ExitMatch<A, E, R>): R => {\n switch (exit._tag) {\n case \"Ok\":\n return handlers.Ok(exit.value)\n case \"Err\":\n return handlers.Err(exit.error)\n case \"Defect\":\n return handlers.Defect(exit.defect)\n }\n})\n\n// ============================================================================\n// Utility\n// ============================================================================\n\n/**\n * Extract the value from an Ok exit, or throw.\n * Useful for tests and scripts where you expect success.\n *\n * @throws The error for Err exits, or the defect for Defect exits\n */\nconst getOrThrow = <A, E>(exit: Exit<A, E>): A => {\n switch (exit._tag) {\n case \"Ok\":\n return exit.value\n case \"Err\":\n // oxlint-disable-next-line only-throw-error -- E is intentionally generic and may be a non-Error domain value.\n throw exit.error\n case \"Defect\":\n throw exit.defect\n }\n}\n\n// ============================================================================\n// Namespace\n// ============================================================================\n\n/**\n * Exit namespace containing all Exit utilities.\n */\nexport const Exit = {\n ok,\n err,\n defect,\n isOk,\n isErr,\n isDefect,\n match,\n getOrThrow,\n} as const\n","import { NoSuchElementError } from \"../option/option.types\"\nimport { asServiceRequest } from \"../service/service-resolution\"\nimport { ok as exitOk, err as exitErr, defect as exitDefect } from \"./exit\"\nimport type { Exit } from \"./exit\"\nimport type { AsyncFx, SyncFx } from \"./fx.types\"\n\nexport function runSync<A, E>(fx: SyncFx<A, E>): Exit<A, E> {\n try {\n const gen = fx[Symbol.iterator]()\n const result = gen.next()\n\n if (result.done !== true) {\n const yielded = result.value as unknown\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n return exitDefect(\n new Error(`Service \"${serviceRequest.key}\" not provided. Use Provide.layer() to inject services.`),\n )\n }\n\n if (yielded instanceof NoSuchElementError) {\n return exitErr(yielded as E)\n }\n\n if (typeof yielded === \"object\" && yielded !== null && \"_tag\" in yielded && yielded._tag === \"Err\") {\n return exitErr((yielded as Record<string, unknown>)[\"error\"] as E)\n }\n\n return exitErr(yielded as E)\n }\n\n return exitOk(result.value)\n } catch (thrown) {\n return exitDefect(thrown)\n }\n}\n\nexport async function runAsync<A, E>(fx: AsyncFx<A, E>): Promise<Exit<A, E>> {\n try {\n const gen = fx[Symbol.asyncIterator]()\n const result = await gen.next()\n\n if (result.done !== true) {\n const yielded = result.value as unknown\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n return exitDefect(\n new Error(`Service \"${serviceRequest.key}\" not provided. Use Provide.layer() to inject services.`),\n )\n }\n\n if (yielded instanceof NoSuchElementError) {\n return exitErr(yielded as E)\n }\n\n if (typeof yielded === \"object\" && yielded !== null && \"_tag\" in yielded && yielded._tag === \"Err\") {\n return exitErr((yielded as Record<string, unknown>)[\"error\"] as E)\n }\n\n return exitErr(yielded as E)\n }\n\n return exitOk(result.value)\n } catch (thrown) {\n return exitDefect(thrown)\n }\n}\n"],"mappings":"yIAyCA,MAAa,EAAS,IAAqB,CAAE,KAAM,KAAM,QAAO,EAKnD,EAAU,IAAsB,CAAE,KAAM,MAAO,QAAO,EAKtD,EAAU,IA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ACtB,OAAO,KAAG,KAAG,SAAO,aAClC,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4BN,uCAAiC,0DACrB,iBAAiB,KAAG,KAAG,qBAC3B,QAAQ,KAAG,KAAG,SAAO,aACnC,YAAY;;;;;;;;;;;;KA+HH;;2BACK,sBAAsB,QAAQ;iBAAoB;OAAS;;;;;;;;;;;;;;;;cA4D/D,YAAG;;;;;;;;;;;;;;cAeH,WAAE;;;;;;;;;;;;;;cAeF,YAAG;;;;;;;;;;;;;;;;;;;;cAqBH;gBAtiBC,iDAAiD,mBAAmB,gBAAc,IAAI,YAAY,MAAI;aACvG,yBACC,kBACG,2CAA2C,SAAO,YAAY,MAAI;;;;;;;;;;;;;;;cAkjBtE;;;;;;;;;;;;;;;;;;;;;;;;;;;cAaA,eAAE,MAAA,OAAA;;;;;;;;;;;;cAaF,kBAAG,QAAA,cAAA;;;;;;;;;;;;cAaH,mBAAM,MAAA,OAAA,YAAA;cAEb,MAAY;;;;;;;;;;;;;;cA+BL;;;iBArKqC,aAAa,YAAY,GAAG,OAAK;;;oBAC9B,YAAY,GAAG,eAAa,MAAM"}
|
|
@@ -1,458 +0,0 @@
|
|
|
1
|
-
import { h as Prettify, t as Result } from "./result.types-BKzChyWY.mjs";
|
|
2
|
-
import { c as ValidationError } from "./schema.types-w1WK4kGS.mjs";
|
|
3
|
-
import { t as Discriminator } from "./discriminator.types-C-ygT2S1.mjs";
|
|
4
|
-
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
|
-
|
|
6
|
-
//#region src/adt/adt.match.d.ts
|
|
7
|
-
/**
|
|
8
|
-
* Handler functions for each variant in a discriminated union.
|
|
9
|
-
* Each key maps to a function that receives the variant value and returns TResult.
|
|
10
|
-
*
|
|
11
|
-
* @template T - The discriminated union type (must have readonly _tag)
|
|
12
|
-
* @template TResult - The return type of all handlers
|
|
13
|
-
*/
|
|
14
|
-
type AdtMatchHandlers<T extends {
|
|
15
|
-
readonly _tag: string;
|
|
16
|
-
}, TResult> = { [K in T["_tag"]]: (value: Extract<T, {
|
|
17
|
-
readonly _tag: K;
|
|
18
|
-
}>) => TResult };
|
|
19
|
-
/**
|
|
20
|
-
* Exhaustive pattern matching for discriminated unions.
|
|
21
|
-
*
|
|
22
|
-
* TypeScript will error if any variant is missing from handlers,
|
|
23
|
-
* ensuring exhaustive handling of all cases.
|
|
24
|
-
*
|
|
25
|
-
* @template T - The discriminated union type (must have readonly _tag)
|
|
26
|
-
* @template TResult - The return type of all handlers
|
|
27
|
-
* @template Handlers - The handler object type (inferred)
|
|
28
|
-
* @param value - A discriminated union value with _tag
|
|
29
|
-
* @param handlers - An object with a handler function for each variant
|
|
30
|
-
* @returns The result of calling the matching handler
|
|
31
|
-
*
|
|
32
|
-
* @see {@link union} for creating discriminated unions
|
|
33
|
-
* @see {@link variant} for creating individual variant types
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { Adt } from "@nicolastoulemont/std"
|
|
38
|
-
* import { z } from "zod"
|
|
39
|
-
*
|
|
40
|
-
* // Adt accepts any Standard Schema-compatible schema, such as zod, valibot, or arktype.
|
|
41
|
-
* const Circle = Adt.variant("Circle", z.object({ radius: z.number() }))
|
|
42
|
-
* const Square = Adt.variant("Square", z.object({ size: z.number() }))
|
|
43
|
-
* const Shape = Adt.union("Shape", { Circle, Square })
|
|
44
|
-
* type Shape = Adt.Infer<typeof Shape>
|
|
45
|
-
*
|
|
46
|
-
* function describeShape(shape: Shape): string {
|
|
47
|
-
* return Adt.match(shape, {
|
|
48
|
-
* Circle: (c) => `Circle with radius ${c.radius}`,
|
|
49
|
-
* Square: (s) => `Square with size ${s.size}`,
|
|
50
|
-
* })
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
declare function match$1<T extends {
|
|
55
|
-
readonly _tag: string;
|
|
56
|
-
}, TResult, Handlers extends AdtMatchHandlers<T, TResult> = AdtMatchHandlers<T, TResult>>(value: T, handlers: Handlers): TResult;
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/adt/adt.types.d.ts
|
|
59
|
-
/**
|
|
60
|
-
* Constraint for custom codec definitions.
|
|
61
|
-
* Ensures codecs have properly typed `to` and `from` methods.
|
|
62
|
-
* Used to constrain the Codecs generic parameter throughout the codebase.
|
|
63
|
-
*/
|
|
64
|
-
type AdtCodecConstraint<Tag$1 extends string, S$1 extends StandardSchemaV1> = Record<string, {
|
|
65
|
-
to: (value: AdtInferOutput<S$1> & Discriminator<Tag$1>) => any;
|
|
66
|
-
from: (input: any) => any;
|
|
67
|
-
}>;
|
|
68
|
-
/**
|
|
69
|
-
* Error type for codec operations.
|
|
70
|
-
* Used when encoding fails or when decoded data fails validation.
|
|
71
|
-
*/
|
|
72
|
-
type AdtCodecError = {
|
|
73
|
-
readonly kind: "EncodingError" | "DecodingError" | "ValidationError";
|
|
74
|
-
readonly message: string;
|
|
75
|
-
readonly cause?: unknown;
|
|
76
|
-
readonly validationIssues?: ValidationError["issues"];
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* Infer the input type from a Standard Schema.
|
|
80
|
-
* This is what the user provides to create().
|
|
81
|
-
*/
|
|
82
|
-
type AdtInferInput<S$1 extends StandardSchemaV1> = NonNullable<S$1["~standard"]["types"]>["input"];
|
|
83
|
-
/**
|
|
84
|
-
* Infer the output type from a Standard Schema.
|
|
85
|
-
* This is what validation returns (after transforms/defaults).
|
|
86
|
-
*/
|
|
87
|
-
type AdtInferOutput<S$1 extends StandardSchemaV1> = NonNullable<S$1["~standard"]["types"]>["output"];
|
|
88
|
-
/**
|
|
89
|
-
* Extract the return type from a codec's `to` method.
|
|
90
|
-
* This is what the encoding function returns (e.g., string, Uint8Array).
|
|
91
|
-
*/
|
|
92
|
-
type ExtractToReturn<C> = C extends {
|
|
93
|
-
to: (value: any) => infer R;
|
|
94
|
-
} ? R : never;
|
|
95
|
-
/**
|
|
96
|
-
* Extract the input type from a codec's `from` method.
|
|
97
|
-
* This is what the decoding function accepts (e.g., string, Uint8Array).
|
|
98
|
-
*/
|
|
99
|
-
type ExtractFromInput<C> = C extends {
|
|
100
|
-
from: (input: infer I) => any;
|
|
101
|
-
} ? I : never;
|
|
102
|
-
/**
|
|
103
|
-
* Build the "to" object containing encoding methods.
|
|
104
|
-
* Always includes 'json' plus any custom codec names.
|
|
105
|
-
* Uses type extraction to infer return types from codec definitions.
|
|
106
|
-
* All methods return Result<T, AdtCodecError> for consistent error handling.
|
|
107
|
-
*/
|
|
108
|
-
type ToMethods<S$1 extends StandardSchemaV1, Codecs> = {
|
|
109
|
-
json: (value: AdtInferInput<S$1>) => Result<string, AdtCodecError>;
|
|
110
|
-
} & (Codecs extends Record<string, any> ? { [K in keyof Codecs]: (value: AdtInferInput<S$1>) => Result<ExtractToReturn<Codecs[K]>, AdtCodecError> } : object);
|
|
111
|
-
/**
|
|
112
|
-
* Build the "from" object containing decoding methods.
|
|
113
|
-
* Always includes 'json' plus any custom codec names.
|
|
114
|
-
* All methods return Result<T, AdtCodecError> for consistent error handling.
|
|
115
|
-
* Uses type extraction to infer input types from codec definitions.
|
|
116
|
-
*/
|
|
117
|
-
type FromMethods<Tag$1 extends string, S$1 extends StandardSchemaV1, Codecs> = {
|
|
118
|
-
json: (input: string) => Result<AdtInferOutput<S$1> & Discriminator<Tag$1>, AdtCodecError>;
|
|
119
|
-
} & (Codecs extends Record<string, any> ? { [K in keyof Codecs]: (input: ExtractFromInput<Codecs[K]>) => Result<AdtInferOutput<S$1> & Discriminator<Tag$1>, AdtCodecError> } : object);
|
|
120
|
-
/**
|
|
121
|
-
* A tagged variant created by the variant() function.
|
|
122
|
-
* Can be used standalone or composed into an AdtUnion via union().
|
|
123
|
-
* Callable as a function to create instances.
|
|
124
|
-
*/
|
|
125
|
-
type AdtVariant<Tag$1 extends string = string, S$1 extends StandardSchemaV1 = StandardSchemaV1, Codecs extends AdtCodecConstraint<Tag$1, S$1> | undefined = undefined> = {
|
|
126
|
-
/** Marker to identify this as a AdtVariant */
|
|
127
|
-
readonly _variant: true;
|
|
128
|
-
/** The _tag discriminator value */
|
|
129
|
-
readonly _tag: Tag$1;
|
|
130
|
-
/** The underlying Standard Schema */
|
|
131
|
-
readonly schema: S$1;
|
|
132
|
-
/** Codec definitions (if provided) */
|
|
133
|
-
readonly codecs?: Codecs;
|
|
134
|
-
/**
|
|
135
|
-
* Create an instance of this variant.
|
|
136
|
-
* @param input - The input data (schema defaults apply)
|
|
137
|
-
* @returns Result with tagged output or validation error
|
|
138
|
-
*/
|
|
139
|
-
(input: AdtInferInput<S$1>): Result<AdtInferOutput<S$1> & Discriminator<Tag$1>, ValidationError>;
|
|
140
|
-
/**
|
|
141
|
-
* Type guard to check if a value is this variant type.
|
|
142
|
-
* @param value - The value to check
|
|
143
|
-
*/
|
|
144
|
-
is(value: unknown): value is AdtInferOutput<S$1> & Discriminator<Tag$1>;
|
|
145
|
-
/**
|
|
146
|
-
* Encoding methods for serializing variant values.
|
|
147
|
-
* Always includes 'json' plus any custom codecs.
|
|
148
|
-
*/
|
|
149
|
-
readonly to: ToMethods<S$1, Codecs>;
|
|
150
|
-
/**
|
|
151
|
-
* Decoding methods for deserializing to variant values.
|
|
152
|
-
* Always includes 'json' plus any custom codecs.
|
|
153
|
-
* All methods validate through the schema before returning.
|
|
154
|
-
*/
|
|
155
|
-
readonly from: FromMethods<Tag$1, S$1, Codecs>;
|
|
156
|
-
/**
|
|
157
|
-
* Compare two instances of this variant for value equality.
|
|
158
|
-
* Performs deep comparison of all fields.
|
|
159
|
-
*/
|
|
160
|
-
equals(a: AdtInferOutput<S$1> & Discriminator<Tag$1>, b: AdtInferOutput<S$1> & Discriminator<Tag$1>): boolean;
|
|
161
|
-
/**
|
|
162
|
-
* Compute a hash code for a variant instance.
|
|
163
|
-
* Equal values always produce the same hash.
|
|
164
|
-
* Useful for Map/Set keys.
|
|
165
|
-
*/
|
|
166
|
-
hash(value: AdtInferOutput<S$1> & Discriminator<Tag$1>): number;
|
|
167
|
-
};
|
|
168
|
-
/**
|
|
169
|
-
* A variant definition can be either:
|
|
170
|
-
* - A raw Standard Schema (will be wrapped internally)
|
|
171
|
-
* - A pre-built AdtVariant from variant()
|
|
172
|
-
*/
|
|
173
|
-
type AdtVariantDef = StandardSchemaV1 | AdtVariant<string, any, any>;
|
|
174
|
-
/**
|
|
175
|
-
* Extract the schema from a AdtVariantDef (handles both raw schema and AdtVariant)
|
|
176
|
-
*/
|
|
177
|
-
type AdtExtractSchema<T extends AdtVariantDef> = T extends AdtVariant<string, infer S, any> ? S : T extends StandardSchemaV1 ? T : never;
|
|
178
|
-
/**
|
|
179
|
-
* Extract the codecs from a AdtVariantDef (if it's a AdtVariant with codecs)
|
|
180
|
-
*/
|
|
181
|
-
type ExtractCodecs<T extends AdtVariantDef> = T extends AdtVariant<string, any, infer Codecs> ? Codecs : undefined;
|
|
182
|
-
/**
|
|
183
|
-
* The AdtUnion returned by union().
|
|
184
|
-
* Contains all variant accessors plus a root type guard.
|
|
185
|
-
* Codecs from variants are preserved in AdtUnion variants.
|
|
186
|
-
*/
|
|
187
|
-
type AdtUnion<R$1 extends Record<string, AdtVariantDef>> = {
|
|
188
|
-
/** The name of this AdtUnion */
|
|
189
|
-
readonly _name: string;
|
|
190
|
-
/**
|
|
191
|
-
* Type guard to check if a value is any variant of this AdtUnion.
|
|
192
|
-
*/
|
|
193
|
-
is(value: unknown): value is InferADTUnion<R$1>;
|
|
194
|
-
/**
|
|
195
|
-
* Compare two AdtUnion values for equality.
|
|
196
|
-
* First checks _tag matches, then compares fields.
|
|
197
|
-
*/
|
|
198
|
-
equals(a: InferADTUnion<R$1>, b: InferADTUnion<R$1>): boolean;
|
|
199
|
-
/**
|
|
200
|
-
* Compute a hash code for any AdtUnion variant.
|
|
201
|
-
*/
|
|
202
|
-
hash(value: InferADTUnion<R$1>): number;
|
|
203
|
-
} & { [K in keyof R$1]: AdtVariant<K & string, AdtExtractSchema<R$1[K]>, ExtractCodecs<R$1[K]>> };
|
|
204
|
-
/**
|
|
205
|
-
* Infer the output type for a single variant within an AdtUnion.
|
|
206
|
-
*/
|
|
207
|
-
type InferRecordOutput<Tag$1 extends string, R$1 extends AdtVariantDef> = AdtInferOutput<AdtExtractSchema<R$1>> & {
|
|
208
|
-
readonly _tag: Tag$1;
|
|
209
|
-
};
|
|
210
|
-
/**
|
|
211
|
-
* Infer the union of all variant output types in an AdtUnion.
|
|
212
|
-
*/
|
|
213
|
-
type InferADTUnion<R$1 extends Record<string, AdtVariantDef>> = { [K in keyof R$1]: InferRecordOutput<K & string, R$1[K]> }[keyof R$1];
|
|
214
|
-
/**
|
|
215
|
-
* AdtInfer types from an AdtUnion or AdtVariant, following Zod's `z.infer` pattern.
|
|
216
|
-
*
|
|
217
|
-
* - For ADTs: Returns the union of all variant types
|
|
218
|
-
* - For AdtVariants: Returns the individual variant type
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* ```ts
|
|
222
|
-
* // AdtInfer union type from AdtUnion
|
|
223
|
-
* const Shape = union('Shape', { Circle, Square })
|
|
224
|
-
* type Shape = AdtInfer<typeof Shape>
|
|
225
|
-
* // => { _tag: 'Circle', radius: number } | { _tag: 'Square', size: number }
|
|
226
|
-
*
|
|
227
|
-
* // Infer individual variant type
|
|
228
|
-
* type Circle = AdtInfer<typeof Shape.Circle>
|
|
229
|
-
* // => { _tag: 'Circle', radius: number }
|
|
230
|
-
* ```
|
|
231
|
-
*/
|
|
232
|
-
type AdtInfer<T> = T extends AdtUnion<infer R> ? Prettify<InferADTUnion<R>> : T extends AdtVariant<infer Tag, infer S> ? Prettify<AdtInferOutput<S> & Discriminator<Tag>> : never;
|
|
233
|
-
/**
|
|
234
|
-
* Extract the union of all variant names from an AdtUnion.
|
|
235
|
-
*
|
|
236
|
-
* @example
|
|
237
|
-
* ```ts
|
|
238
|
-
* const Shape = union('Shape', { Circle, Square })
|
|
239
|
-
* type Names = AdtVariantNames<typeof Shape> // "Circle" | "Square"
|
|
240
|
-
* ```
|
|
241
|
-
*/
|
|
242
|
-
type AdtVariantNames<T> = T extends AdtUnion<infer R> ? keyof R & string : never;
|
|
243
|
-
/**
|
|
244
|
-
* Extract the type of a specific variant from an AdtUnion.
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* ```ts
|
|
248
|
-
* const Shape = union('Shape', { Circle, Square })
|
|
249
|
-
* type CircleType = AdtVariantOf<typeof Shape, "Circle">
|
|
250
|
-
* // => { _tag: "Circle", radius: number }
|
|
251
|
-
* ```
|
|
252
|
-
*/
|
|
253
|
-
type AdtVariantOf<T, K$1 extends string> = T extends AdtUnion<infer R> ? K$1 extends keyof R ? Prettify<AdtInferOutput<AdtExtractSchema<R[K$1]>> & Discriminator<K$1>> : never : never;
|
|
254
|
-
//#endregion
|
|
255
|
-
//#region src/adt/adt.union.d.ts
|
|
256
|
-
/**
|
|
257
|
-
* Compose records or schemas into a discriminated union (AdtUnion).
|
|
258
|
-
*
|
|
259
|
-
* Accepts either:
|
|
260
|
-
* - Pre-built AdtVariants from variant() (codecs are preserved)
|
|
261
|
-
* - Raw Standard Schema validators (will be wrapped internally)
|
|
262
|
-
*
|
|
263
|
-
* When using pre-built records, the object key overrides the original _tag.
|
|
264
|
-
*
|
|
265
|
-
* @template R - Record of variant names to AdtVariants or StandardSchema validators
|
|
266
|
-
* @param name - The name of this AdtUnion (for identification)
|
|
267
|
-
* @param records - An object mapping _tag names to AdtVariants or schemas
|
|
268
|
-
* @returns An AdtUnion object with accessors for each variant
|
|
269
|
-
*
|
|
270
|
-
* @see {@link variant} for creating individual variant types
|
|
271
|
-
* @see {@link match} for exhaustive pattern matching on AdtUnion values
|
|
272
|
-
*
|
|
273
|
-
* @example
|
|
274
|
-
* ```ts
|
|
275
|
-
* // From pre-built variants
|
|
276
|
-
* const Circle = variant('Circle', CircleSchema)
|
|
277
|
-
* const Square = variant('Square', SquareSchema)
|
|
278
|
-
* const Shape = union('Shape', { Circle, Square })
|
|
279
|
-
*
|
|
280
|
-
* // From raw schemas (JSON codec is automatically included)
|
|
281
|
-
* const Shape = union('Shape', {
|
|
282
|
-
* Circle: CircleSchema,
|
|
283
|
-
* Square: SquareSchema
|
|
284
|
-
* })
|
|
285
|
-
*
|
|
286
|
-
* // JSON codec works on all variants
|
|
287
|
-
* Shape.Circle.to.json({ radius: 10 })
|
|
288
|
-
* Shape.Circle.from.json(jsonString)
|
|
289
|
-
*
|
|
290
|
-
* // Mixed
|
|
291
|
-
* const Shape = union('Shape', {
|
|
292
|
-
* Circle, // Pre-built variant
|
|
293
|
-
* Square: SquareSchema // Raw schema
|
|
294
|
-
* })
|
|
295
|
-
*
|
|
296
|
-
* // Usage
|
|
297
|
-
* Shape.Circle({ radius: 10 })
|
|
298
|
-
* Shape.is(someValue) // type guard for any variant
|
|
299
|
-
* Shape.Circle.is(someValue) // type guard for Circle
|
|
300
|
-
* ```
|
|
301
|
-
*/
|
|
302
|
-
declare function union$1<R$1 extends Record<string, AdtVariantDef>>(name: string, records: R$1): AdtUnion<R$1>;
|
|
303
|
-
//#endregion
|
|
304
|
-
//#region src/adt/adt.variant.d.ts
|
|
305
|
-
/**
|
|
306
|
-
* Create a standalone tagged variant from a Standard Schema with optional codecs.
|
|
307
|
-
*
|
|
308
|
-
* Variants can be used independently or composed into an AdtUnion via union().
|
|
309
|
-
* All defaults should be defined at the schema level (e.g., Zod's .default()).
|
|
310
|
-
*
|
|
311
|
-
* @template Tag - The string literal type for the _tag discriminator
|
|
312
|
-
* @template S - The Standard Schema type for validation
|
|
313
|
-
* @template Codecs - Optional codec definitions for custom serialization formats
|
|
314
|
-
* @param _tag - The _tag discriminator value
|
|
315
|
-
* @param schema - A Standard Schema compliant validator
|
|
316
|
-
* @param codecs - Optional codec definitions for custom serialization formats
|
|
317
|
-
* @returns A callable AdtVariant with is(), to, and from methods
|
|
318
|
-
*
|
|
319
|
-
* @see {@link union} for composing variants into discriminated unions
|
|
320
|
-
* @see {@link tagged} for unvalidated tagged value constructors
|
|
321
|
-
*
|
|
322
|
-
* @example
|
|
323
|
-
* ```ts
|
|
324
|
-
* const CircleSchema = z.object({
|
|
325
|
-
* radius: z.number().positive(),
|
|
326
|
-
* color: z.string().default('blue')
|
|
327
|
-
* })
|
|
328
|
-
*
|
|
329
|
-
* // Basic variant with JSON codec (always included)
|
|
330
|
-
* const Circle = variant('Circle', CircleSchema)
|
|
331
|
-
*
|
|
332
|
-
* const result = Circle({ radius: 10 })
|
|
333
|
-
* // { _tag: "Ok", value: { _tag: "Circle", radius: 10, color: "blue" } }
|
|
334
|
-
*
|
|
335
|
-
* Circle.is(someValue) // type guard
|
|
336
|
-
*
|
|
337
|
-
* const json = Circle.to.json({ radius: 10 }) // JSON string
|
|
338
|
-
* const result2 = Circle.from.json(json) // Result<Circle, AdtCodecError>
|
|
339
|
-
*
|
|
340
|
-
* // Variant with custom codec
|
|
341
|
-
* const Circle2 = variant('Circle', CircleSchema, {
|
|
342
|
-
* graphic: {
|
|
343
|
-
* to: (circle) => `(${circle.radius})`,
|
|
344
|
-
* from: (input: string) => {
|
|
345
|
-
* const match = input.match(/^\((\d+)\)$/)
|
|
346
|
-
* return match ? { radius: parseInt(match[1]!) } : null
|
|
347
|
-
* }
|
|
348
|
-
* }
|
|
349
|
-
* })
|
|
350
|
-
*
|
|
351
|
-
* const graphic = Circle2.to.graphic({ radius: 10 }) // "(10)"
|
|
352
|
-
* const result3 = Circle2.from.graphic("(10)") // Result<Circle, AdtCodecError>
|
|
353
|
-
* ```
|
|
354
|
-
*/
|
|
355
|
-
declare function variant$1<Tag$1 extends string, S$1 extends StandardSchemaV1, Codecs extends AdtCodecConstraint<Tag$1, S$1>>(_tag: Tag$1, schema: S$1, codecs: Codecs): AdtVariant<Tag$1, S$1, Codecs>;
|
|
356
|
-
declare function variant$1<Tag$1 extends string, S$1 extends StandardSchemaV1>(_tag: Tag$1, schema: S$1): AdtVariant<Tag$1, S$1>;
|
|
357
|
-
declare namespace adt_d_exports {
|
|
358
|
-
export { Infer, VariantNames, VariantOf, match, union, variant };
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Re-exported ADT inferred union helper.
|
|
362
|
-
*
|
|
363
|
-
* @example
|
|
364
|
-
* ```ts
|
|
365
|
-
* import { Adt } from "@nicolastoulemont/std"
|
|
366
|
-
* import { z } from "zod"
|
|
367
|
-
*
|
|
368
|
-
* // Adt accepts any Standard Schema-compatible schema, such as zod, valibot, or arktype.
|
|
369
|
-
* const Shape = Adt.union("Shape", {
|
|
370
|
-
* Circle: z.object({ radius: z.number() }),
|
|
371
|
-
* })
|
|
372
|
-
* type Shape = Adt.Infer<typeof Shape>
|
|
373
|
-
* ```
|
|
374
|
-
*/
|
|
375
|
-
type Infer<T> = AdtInfer<T>;
|
|
376
|
-
/**
|
|
377
|
-
* Re-exported union variant name helper.
|
|
378
|
-
*
|
|
379
|
-
* @example
|
|
380
|
-
* ```ts
|
|
381
|
-
* import { Adt } from "@nicolastoulemont/std"
|
|
382
|
-
* import { z } from "zod"
|
|
383
|
-
*
|
|
384
|
-
* // Adt accepts any Standard Schema-compatible schema, such as zod, valibot, or arktype.
|
|
385
|
-
* const Shape = Adt.union("Shape", {
|
|
386
|
-
* Circle: z.object({ radius: z.number() }),
|
|
387
|
-
* })
|
|
388
|
-
* type Names = Adt.VariantNames<typeof Shape>
|
|
389
|
-
* ```
|
|
390
|
-
*/
|
|
391
|
-
type VariantNames<T> = AdtVariantNames<T>;
|
|
392
|
-
/**
|
|
393
|
-
* Re-exported helper to extract a specific variant from an ADT.
|
|
394
|
-
*
|
|
395
|
-
* @example
|
|
396
|
-
* ```ts
|
|
397
|
-
* import { Adt } from "@nicolastoulemont/std"
|
|
398
|
-
* import { z } from "zod"
|
|
399
|
-
*
|
|
400
|
-
* // Adt accepts any Standard Schema-compatible schema, such as zod, valibot, or arktype.
|
|
401
|
-
* const Shape = Adt.union("Shape", {
|
|
402
|
-
* Circle: z.object({ radius: z.number() }),
|
|
403
|
-
* })
|
|
404
|
-
* type Circle = Adt.VariantOf<typeof Shape, "Circle">
|
|
405
|
-
* ```
|
|
406
|
-
*/
|
|
407
|
-
type VariantOf<T, K$1 extends string> = AdtVariantOf<T, K$1>;
|
|
408
|
-
/**
|
|
409
|
-
* Build an ADT union from named variants.
|
|
410
|
-
*
|
|
411
|
-
* @example
|
|
412
|
-
* ```ts
|
|
413
|
-
* import { Adt } from "@nicolastoulemont/std"
|
|
414
|
-
* import { z } from "zod"
|
|
415
|
-
*
|
|
416
|
-
* // Adt accepts any Standard Schema-compatible schema, such as zod, valibot, or arktype.
|
|
417
|
-
* const CircleSchema = z.object({ radius: z.number() })
|
|
418
|
-
*
|
|
419
|
-
* const Shape = Adt.union("Shape", { Circle: CircleSchema })
|
|
420
|
-
* const result = Shape.Circle({ radius: 2 })
|
|
421
|
-
* // => { _tag: "Ok", value: { _tag: "Circle", radius: 2 } }
|
|
422
|
-
* ```
|
|
423
|
-
*/
|
|
424
|
-
declare const union: typeof union$1;
|
|
425
|
-
/**
|
|
426
|
-
* Define one ADT variant with schema-backed validation.
|
|
427
|
-
*
|
|
428
|
-
* @example
|
|
429
|
-
* ```ts
|
|
430
|
-
* import { Adt } from "@nicolastoulemont/std"
|
|
431
|
-
* import { z } from "zod"
|
|
432
|
-
*
|
|
433
|
-
* // Adt accepts any Standard Schema-compatible schema, such as zod, valibot, or arktype.
|
|
434
|
-
* const CircleSchema = z.object({ radius: z.number() })
|
|
435
|
-
*
|
|
436
|
-
* const Circle = Adt.variant("Circle", CircleSchema)
|
|
437
|
-
* const result = Circle({ radius: 2 })
|
|
438
|
-
* // => { _tag: "Ok", value: { _tag: "Circle", radius: 2 } }
|
|
439
|
-
* ```
|
|
440
|
-
*/
|
|
441
|
-
declare const variant: typeof variant$1;
|
|
442
|
-
/**
|
|
443
|
-
* Match over ADT variants by discriminator tag.
|
|
444
|
-
*
|
|
445
|
-
* @example
|
|
446
|
-
* ```ts
|
|
447
|
-
* import { Adt } from "@nicolastoulemont/std"
|
|
448
|
-
*
|
|
449
|
-
* const label = Adt.match({ _tag: "Circle", radius: 2 } as const, {
|
|
450
|
-
* Circle: (circle) => `r=${circle.radius}` ,
|
|
451
|
-
* })
|
|
452
|
-
* // => "r=2"
|
|
453
|
-
* ```
|
|
454
|
-
*/
|
|
455
|
-
declare const match: typeof match$1;
|
|
456
|
-
//#endregion
|
|
457
|
-
export { adt_d_exports as t };
|
|
458
|
-
//# sourceMappingURL=index-BaRJVkLo.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-BaRJVkLo.d.mts","names":[],"sources":["../src/adt/adt.match.ts","../src/adt/adt.types.ts","../src/adt/adt.union.ts","../src/adt/adt.variant.ts","../src/adt/adt.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;KAOK,gBAAA,CAAA,UAAgB;EACb,SAAA,IAAA,EAAA,MAAA;CAA4B,EAAA,OAAA,CAAA,GAAA,QAA5B,CAAgD,CAAA,MAAA,CAAA,GAAA,CAAA,KAAA,EAA5B,OAA4B,CAApB,CAAoB,EAAA;EAA5B,SAAA,IAAA,EAA4B,CAA5B;AAAqC,CAAA,CAAA,EAAA,GAAA,OAAA,EAAO;AAsCxE;;;;;;;;;;;;;;ACTA;;;;;;;;AAcA;AAeA;;;;;AAMA;;;;;AAAuG;AAW5E;AAef,iBDpDI,OCoDK,CAAA,UAAA;EAAW,SAAA,IAAA,EAAA,MAAA;CACF,EAAA,OAAA,EAAA,iBDlDX,gBCkDW,CDlDM,CCkDN,EDlDS,OCkDT,CAAA,GDlDoB,gBCkDpB,CDlDqC,CCkDrC,EDlDwC,OCkDxC,CAAA,CAAA,CAAA,KAAA,EDjDrB,CCiDqB,EAAA,QAAA,EDjDR,QCiDQ,CAAA,EDjDG,OCiDH;;;;;;AA9D9B;;AAI+B,KAJnB,kBAImB,CAAA,cAAA,MAAA,EAAA,YAJ8B,gBAI9B,CAAA,GAJkD,MAIlD,CAAA,MAAA,EAAA;EAAf,EAAA,EAAA,CAAA,KAAA,EAAA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