import * as Apply from "fp-ts/Apply"; import * as R from "fp-ts/Record"; import * as TE from "fp-ts/TaskEither"; type EnforceNonEmptyRecord = keyof R extends never ? never : R; export const chainMergeTaskEither = < A extends Record, B extends Record >( o: (a: A) => { readonly [K in keyof B]: TE.TaskEither; } ): ((ma: TE.TaskEither) => TE.TaskEither) => TE.chain((a: A) => { return Apply.sequenceS(TE.ApplyPar)({ ...R.map((v) => TE.of(v))(a), ...o(a), } as EnforceNonEmptyRecord< { readonly [K in keyof B]: TE.TaskEither; } & { readonly [K in keyof A]: TE.TaskEither; } >); }) as (ma: TE.TaskEither) => TE.TaskEither;