UNPKG

typed-utilities

Version:
58 lines (48 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Option = void 0; var _Either = require("./Either"); function isSome(option) { return _Either.Either.is.left(option); } function assertSome(option, message) { if (!isSome(option)) { throw new TypeError(message ?? `option should be 'some'`); } } function isNone(option) { return _Either.Either.is.right(option); } function assertNone(option, message) { if (!isNone(option)) { throw new TypeError(message ?? `option should be 'none'`); } } const toSomeValue = option => option[1]; const is = { some: isSome, none: isNone }; const assert = { some: assertSome, none: assertNone }; const of = { some: value => _Either.Either.of.left(value), none: () => _Either.Either.of.right(null) }; const to = { someValue: toSomeValue }; const match = (option, match) => isSome(option) ? match.some(option[1]) : match.none(); const Option = { is, assert, of, to, match }; exports.Option = Option; //# sourceMappingURL=Option.js.map