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>`.
14 lines (13 loc) • 421 B
JavaScript
import { isSome, unwrapSome } from './option.js';
/**
* Unwraps a result _input_, returns the content of an `Some(T)`.
* If the value is an `None` then it calls `def` with its value.
*/
export async function unwrapOrElseAsyncForOption(input, recoverer) {
if (isSome(input)) {
const val = unwrapSome(input);
return val;
}
const defaultValue = await recoverer();
return defaultValue;
}