diff --git a/src/object_builders.ts b/src/object_builders.ts index 0fa0e4e..9746c6a 100644 --- a/src/object_builders.ts +++ b/src/object_builders.ts @@ -46,6 +46,21 @@ export function objectStepFn() { } } +// utility type to get a Union from a Tuple of types +type UnionFromTuple = Tuple[number] + +// get a union of all the R dependencies from a tuple of steps +type ObjectStepDeps = T extends ObjectStepSpec ? R : never +type ObjectStepsDeps = UnionFromTuple<{ + +readonly [Index in keyof Tuple]: ObjectStepDeps +} & { length: Tuple['length'] }> + +// get a union of all the E errors from a tuple of steps +type ObjectStepErrors = T extends ObjectStepSpec ? E : never +type ObjectStepsErrors = UnionFromTuple<{ + +readonly [Index in keyof Tuple]: ObjectStepErrors +} & { length: Tuple['length'] }> + // build an Object by chaining an initial value through a sequence // of steps, accumulating {K: V} after each step type ChainObjectSteps() { // start with the no-steps fn (obj: Init) => Effect.succeed(obj)) - return r as (obj: Init) => Effect.Effect> + return r as (obj: Init) => Effect.Effect, ObjectStepsErrors, ChainObjectStepsReturn> } } @@ -248,13 +263,12 @@ export function tupleMapObjectStepsProg() { }) } - return r as (inputs: Inputs) => Effect.Effect> + return r as (inputs: Inputs) => Effect.Effect, ObjectStepsErrors, TupleMapObjectStepsReturn> } } // next: -// - bring step R and E out to the top-level types // - combinators to build sequences of ObjectStepSpecs (maybe not at this level - i think // the data-oriented approach is fine at this low level, and combinators can consume/emit // data structures)