Skip to content

tryToMaybe

tryToMaybe<T>(x): T extends Failure ? Nothing : Success<T>

Convert the Try to a Maybe, where Success is converted to Just, and Failure is converted to Nothing.

Example

tryToMaybe("foobar")
// => "foobar"
tryToMaybe(new Error("foobar"))
// => Nothing

Type Parameters

T extends unknown

The value type.

Parameters

x

T

The Try to transform.

Returns

T extends Failure ? Nothing : Success<T>