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) 599 B
import { unsafeUnwrapValueInErrWithoutAnyCheck, unsafeUnwrapValueInOkWithoutAnyCheck, } from './internal/intrinsics_unsafe.js'; import { isOk } from './result.js'; /** * Unwraps a result _input_, returns the content of an `Ok(T)`. * If the value is an `Err(E)` then it calls `def` with its value. */ export function unwrapOrElseForResult(input, recoverer) { if (isOk(input)) { const val = unsafeUnwrapValueInOkWithoutAnyCheck(input); return val; } const err = unsafeUnwrapValueInErrWithoutAnyCheck(input); const fallback = recoverer(err); return fallback; }