UNPKG

option-t

Version:

A toolkit of Nullable/Option/Result type implementation in ECMAScript. Their APIs are inspired by Rust's `Option<T>` and `Result<T, E>`.

16 lines (15 loc) 629 B
import { unsafeUnwrapValueInErrWithoutAnyCheck, unsafeUnwrapValueInOkWithoutAnyCheck, } from './internal/intrinsics_unsafe.js'; import { isOk } from './result.js'; /** * Unwraps _input_, returns the content of an `Ok(T)`. * If the value is an `Err(E)` then it calls `recoverer` with its value. */ export async function unwrapOrElseAsyncForResult(input, recoverer) { if (isOk(input)) { const value = unsafeUnwrapValueInOkWithoutAnyCheck(input); return value; } const error = unsafeUnwrapValueInErrWithoutAnyCheck(input); const defaultValue = await recoverer(error); return defaultValue; }