Skip to content

True Myth / toolbelt / toMaybe

Function: toMaybe() ​

toMaybe<T>(result): Maybe<T>

Convert a Result to a Maybe.

The converted type will be Just if the Result is Ok or Nothing if the Result is Err; the wrapped error value will be discarded.

Type Parameters ​

T ​

T extends object

Parameters ​

result ​

Result<T, unknown>

The Result to convert to a Maybe

Returns ​

Maybe<T>

Just the value in result if it is Ok; otherwise Nothing