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) • 385 B
JavaScript
import { isNotNullOrUndefined } from '../core/maybe.js';
/**
* Return _input_ as `T` if the passed _input_ is not `null` and `undefined`.
* Otherwise, return the result of _recoverer_.
*/
export async function orElseAsyncForMaybe(input, recoverer) {
if (isNotNullOrUndefined(input)) {
return input;
}
const fallback = await recoverer();
return fallback;
}