The input UnknownResult type.
The type returned by the ok case.
The type returned by the err case.
The value produced by whichever case handler was applied.
const doubledOrZero = Result.match(Result.ok(21), {
ok: (value) => value * 2,
err: () => 0,
});
assert.deepStrictEqual(doubledOrZero, 42);
const matcher = Result.match({
ok: (value: number) => value + 1,
err: (error: string) => error.length,
});
assert.deepStrictEqual(matcher(Result.ok(1)), 2);
assert.deepStrictEqual(matcher(Result.err('oops')), 4);
Folds a Result into a plain value by applying one of two case handlers:
ok if the Result is Ok, err otherwise. This is the function form of
pattern matching on a Result.
Unlike Result.fold, which maps both sides and returns another
Result, match unwraps: both branches produce the final value directly.
The type returned by the ok case.
The type returned by the err case.
The value produced by whichever case handler was applied.
const doubledOrZero = Result.match(Result.ok(21), {
ok: (value) => value * 2,
err: () => 0,
});
assert.deepStrictEqual(doubledOrZero, 42);
const matcher = Result.match({
ok: (value: number) => value + 1,
err: (error: string) => error.length,
});
assert.deepStrictEqual(matcher(Result.ok(1)), 2);
assert.deepStrictEqual(matcher(Result.err('oops')), 4);
Folds a
Resultinto a plain value by applying one of two case handlers:okif theResultisOk,errotherwise. This is the function form of pattern matching on aResult.Unlike Result.fold, which maps both sides and returns another
Result,matchunwraps: both branches produce the final value directly.