@kaelyx/ts-kit / result / unwrapOr
Function: unwrapOr()
unwrapOr<
T,E>(result,defaultValue):T
Defined in: result/unwrap-or/unwrap-or.ts:20
Returns the value of a successful Result, or the default value if the Result failed.
Type Parameters
T
T
E
E
Parameters
result
Result<T, E>
The Result to unwrap.
defaultValue
T
The value to return when ok is false.
Returns
T
The value of the Result when ok is true. Otherwise, defaultValue.
Example
ts
unwrapOr(ok(42), 0) // 42
unwrapOr(err('Something went wrong'), 0) // 0