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>`.
10 lines (9 loc) • 320 B
JavaScript
import { isOk } from '../core/result.js';
import { unsafeUnwrapValueInErrWithoutAnyCheck } from './intrinsics_unsafe.js';
export function unwrapErrOrForResult(input, defaultValue) {
if (isOk(input)) {
return defaultValue;
}
const val = unsafeUnwrapValueInErrWithoutAnyCheck(input);
return val;
}