tryCatchK2<A, B, L, R> function
TaskEither<L, R> Function(A a, B b)
tryCatchK2<A, B, L, R>(
- FutureOr<
R> task(- A a,
- B b
- L onError(
- dynamic err,
- StackTrace stackTrace
A variant of tryCatch that accepts two external parameters.
final readFileChunk = tryCatchK2(
(File file, int bytes) => file.read(bytes),
(err, stack) => 'Failed to read file',
);
expect(
await readFileChunk(File('exists.txt'), 5),
right('hello'),
);
expect(
await readFileChunk(File('does not exist.txt'), 5),
left('Failed to read file'),
);
Implementation
TaskEither<L, R> Function(A a, B b) tryCatchK2<A, B, L, R>(
FutureOr<R> Function(A a, B b) task,
L Function(dynamic err, StackTrace stackTrace) onError,
) =>
(a, b) => tryCatch(() => task(a, b), onError);