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>`.

15 lines (14 loc) 515 B
import { unsafeUnwrapValueInErrWithoutAnyCheck } from './internal/intrinsics_unsafe.js'; import { isOk } from './result.js'; /** * Calls _recoverer_ and return its returned value if the result is `Err(E)`, * otherwise returns the `Ok(T)` value of self. */ export async function orElseAsyncForResult(input, recoverer) { if (isOk(input)) { return input; } const inner = unsafeUnwrapValueInErrWithoutAnyCheck(input); const defaultValue = await recoverer(inner); return defaultValue; }