UNPKG

@typed/io

Version:

Runtime IO type system

14 lines 581 B
import { fromRight, isRight } from '@typed/either'; import { toString } from '@typed/strings'; import { catchDecodeFailure, DecodeError, decodeFailure, } from './Decoder'; export const refinement = (decoder, refined, expected) => ({ expected, *decode(i) { const eitherErrorOrA = yield* catchDecodeFailure(decoder.decode(i)); if (isRight(eitherErrorOrA)) { return yield* refined(fromRight(eitherErrorOrA)); } return yield* decodeFailure(DecodeError.create(expected, toString(i))); }, }); //# sourceMappingURL=refinement.js.map