69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
import { bench, describe } from 'vitest';
|
|
import { STANDARD } from '../helpers/bench-options.js';
|
|
import {
|
|
ok,
|
|
err,
|
|
ntOk,
|
|
ntErr,
|
|
TsOk,
|
|
TsErr,
|
|
OxOk,
|
|
OxErr,
|
|
E,
|
|
pipe,
|
|
TmResult,
|
|
} from '../helpers/imports.js';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// toNullable — success path
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Result.toNullable — Ok', () => {
|
|
const nm = ok(42);
|
|
const ox = OxOk(42);
|
|
|
|
bench('native-monad', () => { nm.toNullable(); }, STANDARD);
|
|
// neverthrow: no toNullable — use match or _unsafeUnwrap
|
|
// ts-results-es: no toNullable
|
|
bench('oxide.ts', () => { ox.into(); }, STANDARD);
|
|
bench('fp-ts', () => { pipe(E.right(42), E.toUnion); }, STANDARD);
|
|
bench('true-myth', () => { TmResult.ok<number, string>(42).isOk ? 42 : null; }, STANDARD);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// toNullable — failure path
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Result.toNullable — Err', () => {
|
|
const nm = err('fail');
|
|
const ox = OxErr('fail');
|
|
|
|
bench('native-monad', () => { nm.toNullable(); }, STANDARD);
|
|
bench('oxide.ts', () => { ox.into(); }, STANDARD);
|
|
bench('fp-ts', () => { pipe(E.left('fail'), E.toUnion); }, STANDARD);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// toString
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Result.toString — Ok', () => {
|
|
const nm = ok(42);
|
|
const ox = OxOk(42);
|
|
|
|
bench('native-monad', () => { nm.toString(); }, STANDARD);
|
|
// neverthrow: no toString
|
|
// ts-results-es: no toString
|
|
bench('oxide.ts', () => { ox.toString(); }, STANDARD);
|
|
// fp-ts: no toString
|
|
// true-myth: no toString
|
|
});
|
|
|
|
describe('Result.toString — Err', () => {
|
|
const nm = err('fail');
|
|
const ox = OxErr('fail');
|
|
|
|
bench('native-monad', () => { nm.toString(); }, STANDARD);
|
|
bench('oxide.ts', () => { ox.toString(); }, STANDARD);
|
|
});
|