Skip to content

Tap

Bases: Protocol


              flowchart TD
              pyochain.abc._mixins.Tap[Tap]

              

              click pyochain.abc._mixins.Tap href "" "pyochain.abc._mixins.Tap"
            

Mixin class providing the tap method.

Source code in pyochain/abc/_mixins.pyi
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class Tap(Protocol):
    """Mixin class providing the `tap` method."""
    def tap[**P](
        self,
        func: Callable[Concatenate[Self, P], object],
        *args: P.args,
        **kwargs: P.kwargs,
    ) -> Self:
        """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.

        Args:
            func (Callable[Concatenate[Self, P], object]): Function to apply to the instance for side effects.
            *args (P.args): Positional arguments to pass to **func**.
            **kwargs (P.kwargs): Keyword arguments to pass to **func**.

        Returns:
            Self: The instance itself, unchanged.

        Example:
            ```python
            from pyochain import Seq, Vec

            v = Vec()

            x = Seq(1, 2, 3, 4).tap(v.extend).last()

            assert v == Vec(1, 2, 3, 4)
            assert x == 4
            ```
        """

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, Vec

v = Vec()

x = Seq(1, 2, 3, 4).tap(v.extend).last()

assert v == Vec(1, 2, 3, 4)
assert x == 4
Source code in pyochain/abc/_mixins.pyi
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def tap[**P](
    self,
    func: Callable[Concatenate[Self, P], object],
    *args: P.args,
    **kwargs: P.kwargs,
) -> Self:
    """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.

    Args:
        func (Callable[Concatenate[Self, P], object]): Function to apply to the instance for side effects.
        *args (P.args): Positional arguments to pass to **func**.
        **kwargs (P.kwargs): Keyword arguments to pass to **func**.

    Returns:
        Self: The instance itself, unchanged.

    Example:
        ```python
        from pyochain import Seq, Vec

        v = Vec()

        x = Seq(1, 2, 3, 4).tap(v.extend).last()

        assert v == Vec(1, 2, 3, 4)
        assert x == 4
        ```
    """