tryCatchK<A, L, R> function
TaskEither<L, R> Function(A value)
tryCatchK<A, L, R>(
- FutureOr<
R> task(- A value
- L onError(
- dynamic err,
- StackTrace stackTrace
A variant of tryCatch that accepts an external parameter.
final readFile = tryCatchK(
(File file) => file.read(),
(err, stack) => 'Failed to read file',
);
expect(
await readFile(File('exists.txt')),
right('contents'),
);
expect(
await readFile(File('does not exist.txt')),
left('Failed to read file'),
);
Implementation
TaskEither<L, R> Function(A value) tryCatchK<A, L, R>(
FutureOr<R> Function(A value) task,
L Function(dynamic err, StackTrace stackTrace) onError,
) =>
(a) => tryCatch(() => task(a), onError);