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

17 lines (16 loc) 550 B
import { createSome, isNone, unwrapSome } from './option.js'; /** * Maps a `Option<T>` to `Option<U>` by applying a _transformer_ function * to an contained `Some(T)` value, leaving an `None` value untouched. * * This function can be used to compose the results of two functions. */ export async function mapAsyncForOption(input, transformer) { if (isNone(input)) { return input; } const inner = unwrapSome(input); const result = await transformer(inner); const wrapped = createSome(result); return wrapped; }