tryCatchK<L, R, T> static method
TaskEither<L, R> Function(T a)
tryCatchK<L, R, T>(
- Future<
R> run(- T a
- L onError(
- Object error,
- StackTrace stackTrace
Execute an async function (Future) and convert the result to Either:
- If the execution is successful, returns a Right
- If the execution fails (
throw
), then return a Left based ononError
Used to work with Future and exceptions using Either instead of try
/catch
.
It wraps the TaskEither.tryCatch
factory to make chaining with flatMap
easier.
Implementation
static TaskEither<L, R> Function(T a) tryCatchK<L, R, T>(
Future<R> Function(T a) run,
L Function(Object error, StackTrace stackTrace) onError) =>
(a) => TaskEither.tryCatch(
() => run(a),
onError,
);