from typing import TypeVar, Generic
from pysweet.types import Transform
__all__ = [
'Value_',
]
_A = TypeVar('_A')
_B = TypeVar('_B')
# noinspection PyPep8Naming
[docs]class Value_(Generic[_A]):
"""
Pipeable value.
Args:
val: Wrapped value.
"""
_val: _A
def __init__(self, val: _A):
self._val = val
@property
def val(self) -> _A:
"""
Get underlying value.
>>> Value_(2).val
2
Returns:
Wrapped value.
"""
return self._val
[docs] def pipe(self, f: Transform[_A, _B]) -> 'Value_[_B]':
"""
Transform self with ``f`` immutably.
>>> Value_(2).pipe(lambda x: x + 1).val
3
Args:
f: Function.
Returns:
Transformed ``Value_``.
"""
return Value_(f(self._val))