Box¶
from pymonet.box import Box
box = Box(42) # Box<42>
(box
.map(lambda value: value + 1) # Box<43>
.map(lambda value: str(value)) # Box<"43">
.map(lambda value: value[::-1]) # Box<"34">
.bind(lambda value: "output = " + value)) # "output = 34"
-
class
pymonet.box.
Box
(value: T)¶ Data type for storage any type of data
-
ap
(applicative)¶ Applies the function inside the Box[A] structure to another applicative type.
-
bind
(mapper: Callable[[T], U]) → U¶ Take function and applied this function on current box value and returns mapped value.
- Parameters
mapper (Function(A) -> B) – mapper function
- Returns
new box with mapped value
- Return type
B
-
map
(mapper: Callable[[T], U]) → pymonet.box.Box[~U][U]¶ Take function (A) -> b and applied this function on current box value and returns new box with mapped value.
- Parameters
mapper (Function(A) -> B) – mapper function
- Returns
new box with mapped value
- Return type
Box[B]
-
to_either
()¶ Transform Box into Right either.
- Returns
right Either monad with previous value
- Return type
Right[A]
-
to_lazy
()¶ Transform Box into Lazy with returning value function.
- Returns
not folded Lazy monad with function returning previous value
- Return type
Lazy[Function(() -> A)]
-
to_maybe
()¶ Transform Box into not empty Maybe.
- Returns
non empty Maybe monad with previous value
- Return type
Maybe[A]
-
to_try
()¶ Transform Box into successfull Try.
- Returns
successfull Try monad with previous value
- Return type
Try[A]
-
to_validation
()¶ Transform Box into Validation.
- Returns
successfull Validation monad with previous value
- Return type
Validation[A, []]
-