tryCatchK2<A, B, L, R> function

TaskEither<L, R> Function(A a, B b) tryCatchK2<A, B, L, R>(
  1. FutureOr<R> task(
    1. A a,
    2. B b
    ),
  2. L onError(
    1. dynamic err,
    2. 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);