@typed/io
Version:
Runtime IO type system
17 lines • 696 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.refinement = void 0;
const either_1 = require("@typed/either");
const strings_1 = require("@typed/strings");
const Decoder_1 = require("./Decoder");
exports.refinement = (decoder, refined, expected) => ({
expected,
*decode(i) {
const eitherErrorOrA = yield* Decoder_1.catchDecodeFailure(decoder.decode(i));
if (either_1.isRight(eitherErrorOrA)) {
return yield* refined(either_1.fromRight(eitherErrorOrA));
}
return yield* Decoder_1.decodeFailure(Decoder_1.DecodeError.create(expected, strings_1.toString(i)));
},
});
//# sourceMappingURL=refinement.js.map