UNPKG

@typed/io

Version:

Runtime IO type system

12 lines 590 B
import { fromLeft, fromRight, isLeft, Left, Right } from '@typed/either'; import * as G from '../guard'; import { Decoder } from './Decoder'; import { refinement } from './refinement'; const UnknownEither = Decoder.fromGuard(G.Either, 'Either<unknown, unknown>'); export const either = (left, right) => refinement(UnknownEither, function* (either) { if (isLeft(either)) { return Left.of(yield* left.decode(fromLeft(either))); } return Right.of(yield* right.decode(fromRight(either))); }, `Either<${left.expected}, ${right.expected}>`); //# sourceMappingURL=Either.js.map