@mapcss/preset-svg
Version:
SVG as CSS for MapCSS
88 lines (87 loc) • 1.93 kB
JavaScript
export const OptionType = {
Some: Symbol(':some'),
None: Symbol(':none'),
};
export function Some(val) {
return typeof val === 'undefined'
? none_constructor()
: some_constructor(val);
}
export const None = none_constructor();
function some_constructor(val) {
return {
type: OptionType.Some,
isSome() {
return true;
},
isNone() {
return false;
},
match(fn) {
return fn.some(val);
},
map(fn) {
return some_constructor(fn(val));
},
andThen(fn) {
return fn(val);
},
or(_optb) {
return this;
},
and(optb) {
return optb;
},
unwrapOr(_def) {
return val;
},
unwrap() {
return val;
},
};
}
function none_constructor() {
return {
type: OptionType.None,
isSome() {
return false;
},
isNone() {
return true;
},
match(matchObject) {
const { none } = matchObject;
if (typeof none === 'function') {
return none();
}
return none;
},
map(_fn) {
return none_constructor();
},
andThen(_fn) {
return none_constructor();
},
or(optb) {
return optb;
},
and(_optb) {
return none_constructor();
},
unwrapOr(def) {
if (def == null) {
throw new Error('Cannot call unwrapOr with a missing value.');
}
return def;
},
unwrap() {
throw new ReferenceError('Trying to unwrap None.');
},
};
}
export function isSome(val) {
return val.isSome();
}
export function isNone(val) {
return val.isNone();
}