@typed/io
Version:
Runtime IO type system
19 lines • 742 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.union = void 0;
const either_1 = require("@typed/either");
const strings_1 = require("@typed/strings");
const Decoder_1 = require("./Decoder");
exports.union = (decoders, expected = decoders.map((d) => d.expected).join(' | ')) => ({
expected,
*decode(i) {
for (const { decode } of decoders) {
const either = yield* Decoder_1.catchDecodeFailure(decode(i));
if (either_1.isRight(either)) {
return either_1.fromRight(either);
}
}
return yield* Decoder_1.decodeFailure(Decoder_1.DecodeError.create(expected, strings_1.toString(i)));
},
});
//# sourceMappingURL=Union.js.map