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

19 lines (18 loc) 809 B
import { ERR_MSG_TRANSFORMER_MUST_NOT_RETURN_NO_VAL_FOR_UNDEFINABLE } from './internal/error_message.js'; import { expectNotUndefined, isUndefined, } from './undefinable.js'; /** * Zips _self_ and another `Undefinable` with function _transformer_. * If _self_ is `T` and _other_ is `U`, this method returns the result of _transformer_. * Otherwise, `undefined` is returned. * * @throws {TypeError} * Throws if the _transformer_ returns `undefined`. */ export async function zipWithAsyncForUndefinable(self, other, transformer) { if (isUndefined(self) || isUndefined(other)) { return undefined; } const result = await transformer(self, other); const checked = expectNotUndefined(result, ERR_MSG_TRANSFORMER_MUST_NOT_RETURN_NO_VAL_FOR_UNDEFINABLE); return checked; }