tap method

Pulse<P> tap(
  1. void action(
    1. P payload
    )
)

Executes a side-effect action using the current payload and returns this pulse instance.

This operator allows you to "peek" at the data flowing through a pulse chain without modifying the payload, context, or causal trace. It is primarily used for non-destructive operations like logging or debugging.

When to use

  • Logging: Recording the state of a pulse at a specific point in its lifecycle.
  • Debugging: Inserting breakpoints or print statements into a fluent chain to inspect data.
  • External Triggers: Triggering analytics or external notifications that do not depend on the reactive graph's result.

How it works

The action is executed immediately with the pulse's payload. Because it returns this, you can continue chaining other operators like map or attach seamlessly.

Example

final pulse = Pulse(42)
  .tap((val) => print('Intercepted value: $val'))
  .map((val) => val * 2);

// Output: Intercepted value: 42
// Result: Pulse(84)

Implementation

Pulse<P> tap(void Function(P payload) action) {
  action(payload as P);
  return this;
}