Safely get the value out of the Ok variant of a Result.
Ok
Result
This is the recommended way to get a value out of a Result most of the time.
import { ok, err, unwrapOr } from 'true-myth/result';const anOk = ok<number, string>(12);console.log(unwrapOr(0, anOk)); // 12const anErr = err<number, string>('nooooo');console.log(unwrapOr(0, anErr)); // 0 Copy
import { ok, err, unwrapOr } from 'true-myth/result';const anOk = ok<number, string>(12);console.log(unwrapOr(0, anOk)); // 12const anErr = err<number, string>('nooooo');console.log(unwrapOr(0, anErr)); // 0
The value to use if result is an Err.
result
Err
The Result instance to unwrap if it is an Ok.
The content of result if it is an Ok, otherwise defaultValue.
defaultValue
T The value wrapped in the Ok.
E The value wrapped in the Err.
Safely get the value out of the
Ok
variant of aResult
.This is the recommended way to get a value out of a
Result
most of the time.