Skip to content

Tap

Bases: Protocol


              flowchart TD
              pyochain.rs.Tap[Tap]

              

              click pyochain.rs.Tap href "" "pyochain.rs.Tap"
            

Mixin class providing the tap method.

tap(func, *args, **kwargs)

Pass Self to func, call it, and return Self to continue chaining.

This method is very useful for debugging or passing the instance to other functions for side effects (debugging, IO operations, logging, etc.), without breaking the fluent method chaining.

The return type assume that func does not modify the instance, and that it returns None or any other value that is not used.

Parameters:

Name Type Description Default
func Callable[Concatenate[Self, P], object]

Function to apply to the instance for side effects.

required
*args P.args

Positional arguments to pass to func.

()
**kwargs P.kwargs

Keyword arguments to pass to func.

{}

Returns:

Name Type Description
Self Self

The instance itself, unchanged.

Example
>>> from pyochain import Seq
>>> Seq((1, 2, 3, 4)).tap(print).last()
Seq(1, 2, 3, 4)
4