Skip to content

treeo.Apply

Mixin that adds a .apply() method to the class.

apply(self, f, *rest, *, inplace=False)

apply is a wrapper over treeo.apply that passes self as the second argument.

Parameters:

Name Type Description Default
f Callable[..., NoneType]

The function to apply.

required
*rest ~A

additional pytrees.

()
inplace bool

If True, the input obj is mutated.

False

Returns:

Type Description
~A

A new pytree with the updated Trees or the same input obj if inplace is True.

Source code in treeo/mixins.py
def apply(self: A, f: tp.Callable[..., None], *rest: A, inplace: bool = False) -> A:
    """
    `apply` is a wrapper over `treeo.apply` that passes `self` as the second argument.

    Arguments:
        f: The function to apply.
        *rest: additional pytrees.
        inplace: If `True`, the input `obj` is mutated.

    Returns:
        A new pytree with the updated Trees or the same input `obj` if `inplace` is `True`.
    """
    return tree_m.apply(f, self, *rest, inplace=inplace)