decline-ts
Version:
Composable command-line parser for TypeScript - a (partial) porting of Scala decline using fp-ts
36 lines (35 loc) • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Match = void 0;
const function_1 = require("fp-ts/function");
const URI = 'Match';
const matchFlag = (next) => ({ _tag: 'MatchFlag', next });
const matchOption = (next) => ({
_tag: 'MatchOption',
next,
});
const matchAmbiguous = { _tag: 'MatchAmbiguous' };
const isMatchFlag = (match) => match._tag === 'MatchFlag';
const isMatchOption = (match) => match._tag === 'MatchOption';
const fold = ({ onFlag, onOption, onAmbiguous }) => (fa) => fa._tag === 'MatchFlag'
? onFlag(fa.next)
: fa._tag === 'MatchOption'
? onOption(fa.next)
: onAmbiguous();
const map = (f) => (fa) => function_1.pipe(fa, fold({
onFlag: _ => matchFlag(f(_)),
onOption: _ => matchOption(function_1.flow(_, f)),
onAmbiguous: () => matchAmbiguous,
}));
const map_ = (fa, f) => function_1.pipe(fa, map(f));
const match = { URI, map: map_ };
exports.Match = {
fold,
isMatchFlag,
isMatchOption,
map,
match,
matchAmbiguous,
matchFlag,
matchOption,
};