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