tryCatchK<L, R, T> static method

TaskEither<L, R> Function(T a) tryCatchK<L, R, T>(
  1. Future<R> run(
    1. T a
    ),
  2. L onError(
    1. Object error,
    2. 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 on onError

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,
        );