Skip to content

Commit

Permalink
fix sequence constraints in wrapPureChain
Browse files Browse the repository at this point in the history
  • Loading branch information
mccraigmccraig committed Nov 14, 2023
1 parent be0f376 commit cc7ba70
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/object_builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export type ObjectStepsValueTuple<Tuple extends readonly [...UPObjectStepSpec[]]
// types we output - this gives us:
// 1. easy to understsand errors about constraint failure
// 2. it's safe to use never in the else branches
type ChainObjectSteps<Specs extends readonly [...UPObjectStepSpec[]],
export type ChainObjectSteps<Specs extends readonly [...UPObjectStepSpec[]],
ObjAcc,
StepAcc extends [...UPObjectStepSpec[]] = []> =

Expand Down Expand Up @@ -211,7 +211,7 @@ export function chainObjectStepsProg<Init>() {

// build an Object by independently mapping each Step over corresponding values in an Inputs tuple,
// accumulating outputs in an Object {K: V}
type TupleMapObjectSteps<Specs extends readonly [...UPObjectStepSpec[]],
export type TupleMapObjectSteps<Specs extends readonly [...UPObjectStepSpec[]],
Inputs extends readonly [...any[]],
StepAcc extends [...UPObjectStepSpec[]] = []> =

Expand Down
26 changes: 22 additions & 4 deletions src/pure_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Effect } from "effect"
import { Tagged, Tag } from "./tagged.ts"
import { UPFxFnDeps, UPFxFnErrors, UPFxFnValue } from "./fx_fn.ts"
import { ChainObjectSteps, TupleMapObjectSteps } from "./object_builders.ts"
import { Expand, UnionFromTuple, UPObjectStepSpec, ObjectStepsInputTuple, TupleMapObjectStepsReturn, ObjectStepsDepsU, ObjectStepsErrorsU, ChainObjectStepsReturn, chainObjectStepsProg, tupleMapObjectStepsProg } from "./object_builders.ts"

// business logic is encapsulated in a pure function
Expand Down Expand Up @@ -144,9 +145,18 @@ export function pureWrapperProgram<I extends Tagged>() {
export function wrapPureChain<I extends Tagged>() {
return function <InputStepSpecs extends readonly [...UPObjectStepSpec[]],
OutputStepSpecs extends readonly [...UPObjectStepSpec[]]>
(inputStepSpecs: InputStepSpecs,

// this trick type-checks the param against the specs and stage constraints
(inputStepSpecs: ChainObjectSteps<InputStepSpecs, I> extends readonly [...InputStepSpecs]
? readonly [...InputStepSpecs]
: ChainObjectSteps<InputStepSpecs, I>,

pureFn: (pi: ChainObjectStepsReturn<InputStepSpecs, I>) => ObjectStepsInputTuple<OutputStepSpecs>,
outputStepSpecs: OutputStepSpecs) {

// same trick
outputStepSpecs: TupleMapObjectSteps<OutputStepSpecs, ObjectStepsInputTuple<OutputStepSpecs>> extends readonly [...OutputStepSpecs]
? readonly [...OutputStepSpecs]
: TupleMapObjectSteps<OutputStepSpecs, ObjectStepsInputTuple<OutputStepSpecs>>) {

console.log("CREATE WRAP_PURE_CHAIN", inputStepSpecs, pureFn, outputStepSpecs)
const inputChainProg = chainObjectStepsProg<I>()(inputStepSpecs as any)
Expand All @@ -166,10 +176,18 @@ export function wrapPureChain<I extends Tagged>() {
export function pureWrapperChainProgram<I extends Tagged>() {
return function <InputStepSpecs extends readonly [...UPObjectStepSpec[]],
OutputStepSpecs extends readonly [...UPObjectStepSpec[]]>

(tag: Tag<I>,
inputStepSpecs: InputStepSpecs,

inputStepSpecs: ChainObjectSteps<InputStepSpecs, I> extends readonly [...InputStepSpecs]
? readonly [...InputStepSpecs]
: ChainObjectSteps<InputStepSpecs, I>,

pureFn: (pi: ChainObjectStepsReturn<InputStepSpecs, I>) => ObjectStepsInputTuple<OutputStepSpecs>,
outputStepSpecs: OutputStepSpecs) {

outputStepSpecs: TupleMapObjectSteps<OutputStepSpecs, ObjectStepsInputTuple<OutputStepSpecs>> extends readonly [...OutputStepSpecs]
? readonly [...OutputStepSpecs]
: TupleMapObjectSteps<OutputStepSpecs, ObjectStepsInputTuple<OutputStepSpecs>>) {

return {
tagStr: tag.tag,
Expand Down

0 comments on commit cc7ba70

Please sign in to comment.