Skip to content

True Myth / toolbelt / fromMaybe

Function: fromMaybe() ​

Call Signature ​

fromMaybe<T, E>(errValue, maybe): Result<T, E>

Transform a Maybe into a Result.

If the Maybe is a Just, its value will be wrapped in the Ok variant; if it is a Nothing, the errValue will be wrapped in the Err variant.

Type Parameters ​

T ​

T extends object

E ​

E

Parameters ​

errValue ​

E

A value to wrap in an Err if maybe is a Nothing.

maybe ​

Maybe<T>

The Maybe to convert to a Result.

Returns ​

Result<T, E>

Call Signature ​

fromMaybe<T, E>(errValue): (maybe) => Result<T, E>

Transform a Maybe into a Result.

If the Maybe is a Just, its value will be wrapped in the Ok variant; if it is a Nothing, the errValue will be wrapped in the Err variant.

Type Parameters ​

T ​

T extends object

E ​

E

Parameters ​

errValue ​

E

A value to wrap in an Err if maybe is a Nothing.

Returns ​

(maybe) => Result<T, E>