decline-ts
Version:
Composable command-line parser for TypeScript - a (partial) porting of Scala decline using fp-ts
24 lines (23 loc) • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArgOut = void 0;
const fp_ts_1 = require("fp-ts");
const index_1 = require("./index");
var ArgOut;
(function (ArgOut) {
ArgOut.squish = (argOut) => {
const [a, ...tail] = argOut;
if (fp_ts_1.readonlyArray.isEmpty(tail))
return argOut;
const [b, ...rest] = tail;
if (b === undefined)
return fp_ts_1.readonlyNonEmptyArray.of(a);
if (fp_ts_1.either.isLeft(a) && fp_ts_1.either.isLeft(b)) {
return ArgOut.squish(fp_ts_1.readonlyNonEmptyArray.cons(fp_ts_1.either.left(index_1.Accumulator.orElse(a.left, b.left)), rest));
}
if (fp_ts_1.either.isRight(a) && fp_ts_1.either.isRight(b)) {
return ArgOut.squish(fp_ts_1.readonlyNonEmptyArray.cons(fp_ts_1.either.right(index_1.Accumulator.orElse(a.right, b.right)), rest));
}
return fp_ts_1.readonlyNonEmptyArray.cons(a, ArgOut.squish(fp_ts_1.readonlyNonEmptyArray.cons(b, rest)));
};
})(ArgOut = exports.ArgOut || (exports.ArgOut = {}));