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

13 lines (12 loc) 344 B
import { isSome } from './option.js'; /** * Return _input_ as `T` if the passed _input_ is `Some(T)`. * Otherwise, return the result of _recoverer_. */ export async function orElseAsyncForOption(input, recoverer) { if (isSome(input)) { return input; } const defaultValue = await recoverer(); return defaultValue; }