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) 875 B
import type { AsyncTransformFn, AsyncRecoveryFn } from '../internal/function.js'; import { type Nullable, type NotNull } from './nullable.js'; /** * Return the result of _transformer_ with using _input_ as an argument for it if _input_ is not `null`. * Otherwise, return the result of _recoverer_. * * Basically, this operation is a combination `mapAsync()` and `unwrapOrElseAsync()`. * * * `U` must not be `Nullable<*>`. * * If the result of _transformer_ is `null`, this throw an `Error`. * * If the result of _recoverer_ is null`, this throw an `Error`. * * If you'd like to accept `Nullable<*>` as `U`, use a combination `andThenAsync()` and `orElseAsync()`. */ export declare function mapOrElseAsyncForNullable<T, U>(input: Nullable<T>, recoverer: AsyncRecoveryFn<NotNull<U>>, transformer: AsyncTransformFn<T, NotNull<U>>): Promise<NotNull<U>>;