Semigroups

example_semigroup.py
from pymonet.semigroups import All, First, Map, Sum

All(True).concat(All(False))  # All<False>
All(True).concat(All(True))  # All<True>

All(True) == All(True)  # True
All(True) == All(False)  # False

ingredient1 = Map({'score': Sum(1), 'won': All(True), 'captain': First('captain america')})
ingredient2 = Map({'score': Sum(2), 'won': All(True), 'captain': First('iron man')})
ingredient1.concat(ingredient2)  # Map<{'score': Sum(3), 'won': All(True), 'captain': First('captain america')}>
class pymonet.semigroups.All(value)

All is a Monoid that will combine 2 values of any type using logical conjunction on their coerced Boolean values.

__init__(value)

Initialize self. See help(type(self)) for accurate signature.

concat(semigroup: pymonet.semigroups.All)pymonet.semigroups.All
Parameters

semigroup (All[B]) – other semigroup to concat

Returns

new All with last truly value or first falsy

Return type

All[A | B]

class pymonet.semigroups.One(value)

One is a Monoid that will combine 2 values of any type using logical disjunction OR on their coerced Boolean values.

__init__(value)

Initialize self. See help(type(self)) for accurate signature.

concat(semigroup)
Parameters

semigroup (One[B]) – other semigroup to concat

Returns

new One with first truly value or last falsy

Return type

One[A | B]

class pymonet.semigroups.First(value)

First is a Monoid that will always return the first, value when 2 First instances are combined.

__init__(value)

Initialize self. See help(type(self)) for accurate signature.

concat(semigroup)
Parameters

semigroup (First[B]) – other semigroup to concat

Returns

new First with first value

Return type

First[A]

class pymonet.semigroups.Last(value)

Last is a Monoid that will always return the lastest, value when 2 Last instances are combined.

__init__(value)

Initialize self. See help(type(self)) for accurate signature.

concat(semigroup)
Parameters

semigroup (Last[B]) – other semigroup to concat

Returns

new Last with last value

Return type

Last[A]

class pymonet.semigroups.Map(value)

Map is a Semigroup that will always return contated all values inside Map value

__init__(value)

Initialize self. See help(type(self)) for accurate signature.

concat(semigroup)
Parameters

semigroup (Map[B]) – other semigroup to concat

Returns

new Map with concated all values

Return type

Map[A]

class pymonet.semigroups.Max(value)

Max is a Monoid that will combines 2 numbers, resulting in the largest of the two.

__init__(value)

Initialize self. See help(type(self)) for accurate signature.

concat(semigroup)
Parameters

semigroup (Max[B]) – other semigroup to concat

Returns

new Max with largest value

Return type

Max[A | B]

class pymonet.semigroups.Min(value)

Min is a Monoid that will combines 2 numbers, resulting in the smallest of the two.

__init__(value)

Initialize self. See help(type(self)) for accurate signature.

concat(semigroup)
Parameters

semigroup (Min[B]) – other semigroup to concat

Returns

new Min with smallest value

Return type

Min[A | B]