chainTryCatchK<L, R, R2> function
Either<L, R2> Function(Either<L, R> value)
chainTryCatchK<L, R, R2>(
- R2 f(
- R right
- L onError(
- dynamic error,
- StackTrace stack
Runs the given function, and the result is wrapped in a Right.
If it raises an error, then the onError
callback determines the Left
value.
The returned function accepts an Either, and the transformation is only run if is a Right value.
final catcher = chainTryCatchK(
(int i) => i > 5 ? i : throw 'error',
(err, stack) => 'number too small',
);
expect(
right(10).chain(catcher),
right(10),
);
expect(
right(3).chain(catcher),
left('number too small'),
);
Implementation
Either<L, R2> Function(Either<L, R> value) chainTryCatchK<L, R, R2>(
R2 Function(R right) f,
L Function(dynamic error, StackTrace stack) onError,
) =>
flatMap(tryCatchK(f, onError));