const okFold = TernaryResult.fold(
TernaryResult.ok(2),
(value) => value * 2,
(warn: string) => warn.length,
(error: string) => error.toUpperCase(),
);
const warnFold = TernaryResult.fold(
TernaryResult.warn(2, 'spike'),
(value: number) => value,
(warn: string) => warn.toUpperCase(),
(error: string) => error,
);
assert.deepStrictEqual(okFold, TernaryResult.ok(4));
assert.deepStrictEqual(warnFold, TernaryResult.warn(2, 'SPIKE'));
Applies the provided mapper based on the current variant.
const okFold = TernaryResult.fold(
TernaryResult.ok(2),
(value) => value * 2,
(warn: string) => warn.length,
(error: string) => error.toUpperCase(),
);
const warnFold = TernaryResult.fold(
TernaryResult.warn(2, 'spike'),
(value: number) => value,
(warn: string) => warn.toUpperCase(),
(error: string) => error,
);
assert.deepStrictEqual(okFold, TernaryResult.ok(4));
assert.deepStrictEqual(warnFold, TernaryResult.warn(2, 'SPIKE'));
Applies the provided mapper based on the current variant.