From 1f1afc0f28f309462cbd4a0b27883a6b77213722 Mon Sep 17 00:00:00 2001 From: Matei Adriel <rafaeladriel11@gmail.com> Date: Fri, 20 Dec 2019 14:44:42 +0200 Subject: [PATCH] typescript(option): feat: added a fromNullable helper Signed-off-by: prescientmoon <git@moonythm.dev> --- typescript/option/src/helpers.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/typescript/option/src/helpers.ts b/typescript/option/src/helpers.ts index fb87ce1..09a419f 100644 --- a/typescript/option/src/helpers.ts +++ b/typescript/option/src/helpers.ts @@ -105,3 +105,7 @@ export const flat = <T, U>(option: Option<T>): Option<U> => { always(None) ) } + +export const fromNullable = <T>(value: null | T): Option<T> => { + return value === null ? None : Some(value) +}