1
Fork 0

typescript(option): feat: added a fromArray helper

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-12-20 14:57:46 +02:00 committed by prescientmoon
parent 689c746682
commit 15f54ea45f
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4

View file

@ -116,3 +116,7 @@ export const flat = <T, U>(option: Option<T>): Option<U> => {
export const fromNullable = <T>(value: Nullable<T>): Option<T> => {
return value === null ? None : Some(value)
}
export const fromArray = <T>(value: [T] | []): Option<T> => {
return value[0] === undefined ? None : Some(value[0])
}