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

17 lines (16 loc) 569 B
import { createErr, createOk } from '../../plain_result/core/result.js'; /** * Transforms the `Option<T>` into a `Result<T, E>`, * mapping `Some(v)` to `Ok(v)` and None to Err(err). * * Arguments passed to this are eagerly evaluated; * if you are passing the result of a function call, it is recommended to use okOrElse, which is lazily evaluated. */ export function okOrForPlainOption(input, err) { if (input.ok) { const okWrapped = createOk(input.val); return okWrapped; } const errWrapped = createErr(err); return errWrapped; }