import { Compact } from '@typed/common' import { Left, unpack } from '@typed/either' import { chain as chainEnv, Pure } from '@typed/env' import { curry } from '@typed/lambda' import { Future } from './Future' export const chain = curry(__chain) as { (fn: (value: B) => Future, future: Future): Future< Compact, A, C > (fn: (value: B) => Future): ( future: Future, ) => Future, A, C> } function __chain( fn: (value: A) => Future, future: Future, ): Future, C, D> { return chainEnv( (either) => unpack((error) => Pure.of(Left.of(error)) as Future, fn, either), future, ) }