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>`.
30 lines (29 loc) • 1.41 kB
JavaScript
/**
* This module provies that the Result/Either type interface whose APIs are inspired
* by Rust's [`std::result::Result<T, E>`](https://doc.rust-lang.org/std/result/index.html).
*
* We don't use a class to provides this module by these reason:
*
* - Make treeshaking friendly.
* - Almost minifier cannot remove functions by default on `.prototype` even if they are unused.
* - Relax the incompatible problem by mixing multiple versions of this package
* in module dependency tree.
* - e.g. `instanceof` will be a problem. See ([#337](https://github.com/option-t/option-t/pull/337)).
*
* And some operators might not return a new object and reuse the input
* to reduce an object allocation. Thus comparing _this `Option<T>`` is meaningless like a following code.
* This is by design because we think this pattern is meaningless.
*
* ```typescript
* const a: Result<number, string> = createOk(1);
* const b: Result<number, string> = someOperator(a);
*
* // Results of these comparison are undefined.
* a === b;
* Object.is(a, b);
* ```
*/
// We expose _core primitive_ directly.
export { createErr, createOk, expectErr, expectOk, isErr, isOk, unwrapErr, unwrapOk, } from './core/result.js';
// We expose _operators_ (typically named as `~ForResult`) as bundled.
export * as ResultOperator from './internal/intermediate_operators.js';