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) 518 B
import { isNone, unwrapSome } from './option.js'; /** * Return the result of _transformer_ with using _input_ as an argument for it if _input_ is `Some(T)`. * Otherwise, return _defaultValue_. * * Basically, this operation is a combination `map()` and `unwrapOr()`. */ export async function mapOrAsyncForOption(input, defaultValue, transformer) { if (isNone(input)) { return defaultValue; } const inner = unwrapSome(input); const result = await transformer(inner); return result; }