tryCatchK<A, B> function

TaskOption<B> Function(A value) tryCatchK<A, B>(
  1. FutureOr<B> task(
    1. A value
    )
)

A variant of tryCatch, that allows external values to be passed in.

final catcher = tryCatchK((int i) => i > 5 ? i : throw 'too small!');

expect(
  await catcher(10)(),
  O.some(10),
);
expect(
  await catcher(3)(),
  O.none(),
);

Implementation

TaskOption<B> Function(A value) tryCatchK<A, B>(
  FutureOr<B> Function(A value) task,
) =>
    (a) => tryCatch(() => task(a));