derw
Version:
An Elm-inspired language that transpiles to TypeScript
48 lines (47 loc) • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.andThen = exports.withDefault = exports.map = exports.Nothing = exports.Just = void 0;
function Just(args) {
return Object.assign({ kind: "Just" }, args);
}
exports.Just = Just;
function Nothing(args) {
return Object.assign({ kind: "Nothing" }, args);
}
exports.Nothing = Nothing;
function map(fn, maybe) {
switch (maybe.kind) {
case "Just": {
const { value } = maybe;
return Just({ value: fn(value) });
}
case "Nothing": {
return Nothing({});
}
}
}
exports.map = map;
function withDefault(defaultValue, maybe) {
switch (maybe.kind) {
case "Just": {
const { value } = maybe;
return value;
}
case "Nothing": {
return defaultValue;
}
}
}
exports.withDefault = withDefault;
function andThen(fn, maybe) {
switch (maybe.kind) {
case "Just": {
const { value } = maybe;
return fn(value);
}
case "Nothing": {
return Nothing({});
}
}
}
exports.andThen = andThen;