| |
- pymonad.monad.Monad(typing.Generic)
-
- Writer(pymonad.monad.Monad, typing.Generic)
- typing.Generic(builtins.object)
-
- Writer(pymonad.monad.Monad, typing.Generic)
class Writer(pymonad.monad.Monad, typing.Generic) |
|
Writer(*args, **kwds)
The Writer monad class. |
|
- Method resolution order:
- Writer
- pymonad.monad.Monad
- typing.Generic
- builtins.object
Methods defined here:
- __eq__(self, other)
- Return self==value.
- __repr__(self)
- Return repr(self).
- bind(self: 'Writer[M, S]', kleisli_function: Callable[[~S], ForwardRef('Writer[M, T]')]) -> 'Writer[M, T]'
- See Monad.bind.
- map(self: 'Writer[M, S]', function: Callable[[~S], ~T]) -> 'Writer[M, T]'
- See Monad.map.
Class methods defined here:
- insert(value: ~T) -> 'Writer[M, T]' from builtins.type
- See Monad.insert.
Data and other attributes defined here:
- __hash__ = None
- __orig_bases__ = (<class 'pymonad.monad.Monad'>, typing.Generic[~M, ~T])
- __parameters__ = (~M, ~T)
Methods inherited from pymonad.monad.Monad:
- __init__(self, value, monoid)
- Initializes the internal values of the monad instance.
All monads can be expressed as a tuple, (a, m). Representing
all monads internally in this canonical form allows for some
interesting effects such as easily aliasing existing monads
instances and, if desired, adding operators. Occasionally it
also makes implementation of the monad methods itself easier.
Args:
value: if we think of monads as storing some data of
interest plus some 'meta data', then 'value' is the data of
interest. Exactly what 'value' is/means will depend on the
specific context of the monad in question.
monoid: this is the 'meta data' part. While implementers may
use an instance of the Monoid class here it is not
required. However, the value passed in here should be a type
that can be treated as a monoid, such as integers; strings;
lists; etc., in order to ensure that the monad laws are
obeyed. This is not enforced but it will result in an
incorrect implementation.
- amap(self: 'Monad[Callable[[S], T]]', monad_value: 'Monad[S]') -> 'Monad[T]'
- Applies the function stored in the functor to the value inside 'functor_value'
returning a new functor value.
- join(self: 'Monad[Monad[T]]') -> 'Monad[T]'
- Unpacks a nested monad instance one level.
- then(self: 'Monad[S]', function: Union[Callable[[~S], ~T], Callable[[~S], ForwardRef('Monad[T]')]]) -> 'Monad[T]'
- Combines the functionality of bind and fmap.
Instead of worrying about whether to use bind or fmap,
users can just use the then method to chain function
calls together. The then method uses attempts to use
bind first and if that doesn't work, uses fmap
instead.
Args:
function: A python function or lambda expression
which returns either a build-in type (int, string,
etc.) or an appropriate monad type (Maybe, Either,
etc.)
Returns:
A monad value of the same type as 'self'
Class methods inherited from pymonad.monad.Monad:
- apply(function) from builtins.type
- Supplies a cleaner interface for applicative functor/amap usage.
Example:
@curry(2)
def add(a, b): return a + b
x = Just(1)
y = Just(2)
(Maybe.apply(add)
.to_arguments(x, y)
) # results in Just(3)
Args:
function: A regular function which returns non-monadic values.
Returns:
A monad object based on the input class with the wrapped
function and a new method, 'to_arguments' which will apply
the function.
Data descriptors inherited from pymonad.monad.Monad:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Class methods inherited from typing.Generic:
- __class_getitem__(params) from builtins.type
- __init_subclass__(*args, **kwargs) from builtins.type
- This method is called when a class is subclassed.
The default implementation does nothing. It may be
overridden to extend subclasses.
Static methods inherited from typing.Generic:
- __new__(cls, *args, **kwds)
- Create and return a new object. See help(type) for accurate signature.
| |