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

15 lines (14 loc) 447 B
import { createSome } 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 function mapForOption(input, transformer) { if (!input.ok) { return input; } const result = transformer(input.val); return createSome(result); }