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) 520 B
import { unwrapErrOrForResult } from '../internal/unwrap_err_or.js'; import { unwrapOrForResult } from './unwrap_or.js'; /** * Unwrap `T` if _input_ is `Ok(T)`. * Otherwise, return `undefined`. */ export function toUndefinableFromOk(input) { const val = unwrapOrForResult(input, undefined); return val; } /** * Unwrap `E` if _input_ is `Err(E)`. * Otherwise, return `undefined`. */ export function toUndefinableFromErr(input) { const err = unwrapErrOrForResult(input, undefined); return err; }