diff --git a/ambar-core/src/maybe.ts b/ambar-core/src/maybe.ts index 2e5a9e3..1feba96 100644 --- a/ambar-core/src/maybe.ts +++ b/ambar-core/src/maybe.ts @@ -21,6 +21,7 @@ export { CallableJust as Just, CallableNothing as Nothing, from, + fromNullable, catMaybes, mapMaybe, }; @@ -99,6 +100,14 @@ function from(v: undefined | T): Maybe { } } +function fromNullable(v: NonNullable | null): Maybe { + if (v === null) { + return new Nothing(); + } else { + return new Just(v); + } +} + // Remove Nothings from an array. function catMaybes(xs: Array>): Array { const r: Array = [];