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) • 867 B
TypeScript
import type { AsyncTransformFn } from '../../internal/function.js';
import { type Undefinable, type NotUndefined } from '../core/undefinable.js';
/**
* Return the result of _transformer_ with using _input_ as an argument for it if _input_ is not `undefined`.
* Otherwise, return _defaultValue_.
*
* Basically, this operation is a combination `map()` and `unwrapOr()`.
*
* * `U` must not be `Undefinable<*>`.
* * If the result of _transformer_ is `undefined`, this throw an `Error`.
* * If the result of _defaultValue_ is `undefined`, this throw an `Error`.
* * If you'd like to accept `Undefinable<*>` as `U`, use a combination `andThen()` and `or()`.
*/
export declare function mapOrAsyncForUndefinable<T, U>(input: Undefinable<T>, defaultValue: NotUndefined<U>, transformer: AsyncTransformFn<T, NotUndefined<U>>): Promise<NotUndefined<U>>;