typescript(option): feat: added a fromArray helper
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
689c746682
commit
15f54ea45f
|
@ -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])
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue