apfel.container.value
apfel.container.value provides a container that simply wraps a value
designed to aid chained method calls.
See also Identity.
API#
Classes
| Name | Description |
|---|---|
Value | No description. |
Valueclass#
class Value(value: T)Bases: Monad
__doc__attributeinstance attribute#
__doc__ = value.__doc____slots__attributeclass attributeinstance attribute#
__slots__ = ('_value')__class_getitem__method#
def __class_getitem__(item: type[U]) -> Value[U]__init__method#
def __init__(value: T)__repr__method#
def __repr__()__str__method#
def __str__()applymethod#
def apply(func: Value[Callable[[T], R]], /) -> Value[R]Apply a function wrapped inside a Value to the inner value.
Implementation of Applicative.apply.
Returns
Value[R]- Value[R]: A new
Valuecontaining the result of the function application.
bindmethod#
def bind(func: Callable[[T], Value[R]], /) -> Value[R]Monadically bind a function that maps the inner value to a new Value.
Implementation of Monad.bind.
Parameters
Returns
Value[R]- Value[R]: A new
Valuecontaining the result of the function.
donemethod#
def done() -> TReturn the value wrapped inside the container.
Unlike unwrap methods on other containers, this method will never raise
exceptions.
mapmethod#
def map(func: Callable[[T], U], /) -> Value[U]Map a function over the Value container. Implementation of Functor.map.
Parameters
| Name | Type | Description |
|---|---|---|
func | Callable[[T], U] | A function to transform the inner value. |
Returns
Value[U]- Value[U]: A new
Valuecontaining the transformed value.
mutatemethod#
def mutate(func: Callable[[T], Any], /) -> SelfCall a function to mutate the inner value in place.
The function’s return value is ignored, and the container keeps the
original inner reference.
This is similar to Value.tap,
just hinting the mutating intention of the function.
Returns
Self- Value[T]: The mutated container itself.
puremethodclassmethod#
def pure(value: R | T, /) -> Value[R] | Value[T]Wrap a value into the Value container.
Implementation of Applicative.pure.
Parameters
| Name | Type | Description |
|---|---|---|
value | T | The value to wrap. |
runmethod#
def run(func: Callable[[T], R], /) -> RRun a function to process the inner value, and return the result.
Parameters
| Name | Type | Description |
|---|---|---|
func | Callable[[T], R] | A function to process the value. |
Returns
R- The result of the function.
tapmethod#
def tap(func: Callable[[T], Any], /) -> Value[T]Call a function over the inner value, ignore the return value, and return the original container.
See also also.
updatemethod#
def update(func: Callable[[T], T], /) -> SelfUpdate the inner value with the result of a function.
Parameters
| Name | Type | Description |
|---|---|---|
func | Callable[[T], T] | A function to transform the inner value. |
Returns
Self- Value[T]: The mutated container itself.
