treex.Apply
Mixin that adds a .apply()
method to the class.
Source code in treeo/mixins.py
class Apply:
"""
Mixin that adds a `.apply()` method to the class.
"""
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 api.apply(f, self, *rest, inplace=inplace)
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 |
False |
Returns:
Type | Description |
---|---|
~A |
A new pytree with the updated Trees or the same input |
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 api.apply(f, self, *rest, inplace=inplace)