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

22 lines (21 loc) 557 B
import { createOk, isOk } from '../../plain_result/core/result.js'; import { isNullOrUndefined } from '../core/maybe.js'; /** * Transposes a `Maybe` of a `Result` into an `Result` of a `Maybe`. * * - `null` -> `Ok<null>`. * - `undefined` -> `Ok<undefined>` * - `Ok<T>` -> `Ok<T>`. * - `Err<E>` -> `Err<E>`. */ export function transposeMaybeToResult(input) { if (isNullOrUndefined(input)) { return createOk(input); } if (isOk(input)) { const rv = input; return rv; } const rv = input; return rv; }