import { Either, fromLeft, fromRight, isRight } from '@typed/either' import { Env } from '@typed/env' import { Effect, Effects } from '../Effect' import { fail } from './fail' import { FailEnv } from './Failure' export function* orFail( key: F, effect: Effects>, ): Effect | Env, any>, C> { const either = yield* effect if (isRight(either)) { return fromRight(either) } return yield* fail(key, fromLeft(either)) }