From 15f54ea45fd4d6ddc9c3c2b186db986991d2ca8b Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Fri, 20 Dec 2019 14:57:46 +0200 Subject: [PATCH] typescript(option): feat: added a fromArray helper Signed-off-by: prescientmoon --- 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 629e830..296edd2 100644 --- a/typescript/option/src/helpers.ts +++ b/typescript/option/src/helpers.ts @@ -116,3 +116,7 @@ export const flat = (option: Option): Option => { export const fromNullable = (value: Nullable): Option => { return value === null ? None : Some(value) } + +export const fromArray = (value: [T] | []): Option => { + return value[0] === undefined ? None : Some(value[0]) +}