From 37e077a6679a17fcec2f3f86df4e74b4237a91f4 Mon Sep 17 00:00:00 2001 From: Marcelo Lazaroni Date: Mon, 24 Nov 2025 22:08:39 +0000 Subject: [PATCH 1/3] Implement fromNullable for Maybe --- ambar-core/src/maybe.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ambar-core/src/maybe.ts b/ambar-core/src/maybe.ts index 2e5a9e3..0cbf62c 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: Nullable): Maybe { + if (typeof v === null) { + return new Nothing(); + } else { + return new Just(v as T); + } +} + // Remove Nothings from an array. function catMaybes(xs: Array>): Array { const r: Array = []; From 0812e5fdc0b60be0ec8796584c00dd514e2ef3ee Mon Sep 17 00:00:00 2001 From: Marcelo Lazaroni Date: Mon, 24 Nov 2025 22:14:43 +0000 Subject: [PATCH 2/3] Fix implementation --- ambar-core/src/maybe.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ambar-core/src/maybe.ts b/ambar-core/src/maybe.ts index 0cbf62c..0bdc796 100644 --- a/ambar-core/src/maybe.ts +++ b/ambar-core/src/maybe.ts @@ -100,11 +100,11 @@ function from(v: undefined | T): Maybe { } } -function fromNullable(v: Nullable): Maybe { - if (typeof v === null) { +function fromNullable(v: T | null): Maybe { + if (v === null) { return new Nothing(); } else { - return new Just(v as T); + return new Just(v); } } From 0984bfd83bec9652b125c3fdf3c498c97103b0d9 Mon Sep 17 00:00:00 2001 From: Marcelo Lazaroni Date: Mon, 24 Nov 2025 23:35:20 +0000 Subject: [PATCH 3/3] Add NonNullable constraint --- ambar-core/src/maybe.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ambar-core/src/maybe.ts b/ambar-core/src/maybe.ts index 0bdc796..1feba96 100644 --- a/ambar-core/src/maybe.ts +++ b/ambar-core/src/maybe.ts @@ -100,7 +100,7 @@ function from(v: undefined | T): Maybe { } } -function fromNullable(v: T | null): Maybe { +function fromNullable(v: NonNullable | null): Maybe { if (v === null) { return new Nothing(); } else {