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

20 lines (19 loc) 633 B
import { unsafeUnwrapValueInOkWithoutAnyCheck } from './internal/intrinsics_unsafe.js'; import { isErr } from './result.js'; /** * Returns `Err(E)` if the _input_ is `Err(E)`, * otherwise calls _transformer_ with the value and returns the result. * * XXX: * Some languages call this operation flatmap. * But we don't provide `flatMap()` as alias of this function * to sort with other APIs. */ export function andThenForResult(input, transformer) { if (isErr(input)) { return input; } const val = unsafeUnwrapValueInOkWithoutAnyCheck(input); const result = transformer(val); return result; }