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

21 lines (20 loc) 546 B
import { createOk, isOk } from '../../plain_result/core/result.js'; import { isUndefined } from '../core/undefinable.js'; /** * Transposes a `Undefinable` of a `Result` into an `Result` of a `Undefinable`. * * - `undefined` -> `Ok<undefined>`. * - `Ok<T>` -> `Ok<T>`. * - `Err<E>` -> `Err<E>`. */ export function transposeUndefinableToResult(input) { if (isUndefined(input)) { return createOk(undefined); } if (isOk(input)) { const rv = input; return rv; } const rv = input; return rv; }