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>`.
13 lines (12 loc) • 333 B
JavaScript
/**
* 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 function unwrapOrElseForOption(input, recoverer) {
if (input.ok) {
const val = input.val;
return val;
}
const fallback = recoverer();
return fallback;
}