Value#
apfel.container.value provides a container that simply wraps a value
designed to aid chained method calls.
See also Identity.
Value
#
apply(f)
#
bind(f)
#
done()
#
Return the value wrapped inside the container.
Unlike unwrap methods on other containers, this method will never raise
exceptions.
map(f)
#
Map a function over the Value container.
pipe(func)
#
Run a function to process the inner value. If a result is produced, the result will be put back to the container. Otherwise, the original reference within the container will be kept.
Warning
Compare to Value.map, this method
mutates the container in place. No new container is created.
Therefore, the function must return a result of the same type as the
previous inner type of the container, or return None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[T], T] | Callable[[T], None]
|
A function to process the value. |
required |
Returns:
| Type | Description |
|---|---|
Value[T]
|
The mutated container itself. |
pure(x)
classmethod
#
Wrap a value into the Value container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
T
|
The value to wrap. |
required |
Returns:
| Type | Description |
|---|---|
Value[T]
|
A new instance of |
run(func)
#
Run a function to process the inner value, and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[T], R]
|
A function to process the value. |
required |
Returns:
| Type | Description |
|---|---|
R
|
The result of the function. |
tap(func)
#
Call a function over the inner value, ignore the return value, and return the original container.
See also also.
Warning
Pragmatically, the function shouldn't mutate the inner value.
Use the Value.pipe method instead.