UNPKG

derw

Version:

An Elm-inspired language that transpiles to TypeScript

53 lines (52 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Just = Just; exports.Nothing = Nothing; exports.map = map; exports.withDefault = withDefault; exports.andThen = andThen; function Just(args) { return { kind: "Just", ...args, }; } function Nothing(args) { return { kind: "Nothing", ...args, }; } function map(fn, maybe) { switch (maybe.kind) { case "Just": { const { value } = maybe; return Just({ value: fn(value) }); } case "Nothing": { return Nothing({}); } } } function withDefault(defaultValue, maybe) { switch (maybe.kind) { case "Just": { const { value } = maybe; return value; } case "Nothing": { return defaultValue; } } } function andThen(fn, maybe) { switch (maybe.kind) { case "Just": { const { value } = maybe; return fn(value); } case "Nothing": { return Nothing({}); } } }