tap<A> function

TapFunction<A> tap<A>(
  1. void f(
    1. A
    )
)

Transforms a task into another task after performing a side effect.

Example:

Task<int> sampleTask = Task<int>(() => Future.value(10));
Task<int> newTask = tap<int>((value) => print(value))(sampleTask); // Prints the result and returns the same task.

Implementation

TapFunction<A> tap<A>(void Function(A) f) {
  return (Task<A> task) {
    task.task().then(f).catchError((_) {});
    return task;
  };
}