tryCatchK<A, L, R> function

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