tryCatchK<A, L, R> function
Either<L, R> Function(A value)
tryCatchK<A, L, R>(
- R f(
- A value
- 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 function accepts an externally passed value.
final catcher = tryCatchK(
(int i) => i > 5 ? i : throw 'error',
(err, stack) => 'number too small',
);
expect(
catcher(10),
right(10),
);
expect(
catcher(3),
left('number too small'),
);
Implementation
Either<L, R> Function(A value) tryCatchK<A, L, R>(
R Function(A value) f,
L Function(dynamic error, StackTrace stack) onError,
) =>
(value) => tryCatch(() => f(value), onError);