pymonad.monoid
index
/usr/home/jason/Files/projects/pymonad/pymonad/monoid.py

Monoid Implementation.
 
A monoid is an algebraic structure consisting of a set of objects, S,
and an operation usually denoted as '+' which obeys the following
rules:
 
    1. Closure: If 'a' and 'b' are in S, then 'a + b' is also in S.
    2. Identity: There exists an element in S (denoted 0) such that
       a + 0 = a = 0 + a
    3. Associativity: (a + b) + c = a + (b + c)
 
The monoid module provides a generic zero/identity element called
IDENTITY.
 
Monoid addition with IDENTITY simply always returns the other element
regardless of type.
 
Example:
    IDENTITY == IDENTITY # True.
    IDENTITY + 10      # 10
    'hello' + IDENTITY # 'hello'

 
Classes
       
typing.Generic(builtins.object)
Monoid

 
class Monoid(typing.Generic)
    Monoid(*args, **kwds)
 
Base class for Monoid instances.
 
To implement a monoid instance, create a sub-class of Monoid and
override the identity_element and addition_operation methods
ensuring that the closure, identity, and associativity laws hold.
 
 
Method resolution order:
Monoid
typing.Generic
builtins.object

Methods defined here:
__add__(self: Union[ForwardRef('Monoid[T]'), ForwardRef('_MonoidIdentity')], other: Union[ForwardRef('Monoid[T]'), ForwardRef('_MonoidIdentity')]) -> Union[ForwardRef('Monoid[T]'), ForwardRef('_MonoidIdentity')]
__eq__(self: Union[ForwardRef('_MonoidIdentity'), ForwardRef('Monoid[T]')], other: Union[ForwardRef('_MonoidIdentity'), ForwardRef('Monoid[T]')]) -> bool
Return self==value.
__init__(self, value: ~T) -> None
Initialize self.  See help(type(self)) for accurate signature.
addition_operation(self: Union[ForwardRef('Monoid[T]'), ForwardRef('_MonoidIdentity')], other: Union[ForwardRef('Monoid[T]'), ForwardRef('_MonoidIdentity')]) -> Union[ForwardRef('Monoid[T]'), ForwardRef('_MonoidIdentity')]
Defines how monoid values are added together.
 
addition_operation() method is automatically called by
__add__() so monoid values are typically combined using the +
operator and not addition_operation() directly.
 
This method must be overridden in subclasses of Monoid.
 
Args:
  other: a monoid value of the same type as self.
 
Returns:
  Another monoid value of the same type as self and other.

Static methods defined here:
identity_element() -> 'Monoid[Any]'
Returns the identity value for the monoid type.
 
This method must be overridden in subclasses of Monoid.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
__hash__ = None
__orig_bases__ = (typing.Generic[~T],)
__parameters__ = (~T,)

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.

 
Functions
       
mconcat(monoid_list: List[Union[ForwardRef('Monoid[T]'), ForwardRef('_MonoidIdentity')]]) -> Union[ForwardRef('Monoid[T]'), ForwardRef('_MonoidIdentity')]
Takes a list of monoid values and reduces them to a single value
by applying the '+' operation to all elements of the list.

 
Data
        Any = typing.Any
IDENTITY = IDENTITY
List = typing.List
MonoidT = typing.Union[ForwardRef('Monoid[T]'), ForwardRef('_MonoidIdentity')]
T = ~T
Union = typing.Union