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