API

Typeclasses

categories.semigroup.instance(type, sappend)[source]
categories.monoid.instance(type, mempty, mappend)[source]
categories.functor.instance(type, fmap)[source]
categories.applicative.instance(type, pure, apply)[source]
categories.monad.instance(type, mreturn, bind)[source]

Data Types

class categories.maybe.Maybe(type: str, value: A = None)[source]
class categories.either.Either(type: str, value: Union[E, A])[source]
class categories.validation.Validation(type: str, value: Union[E, A])[source]

Utilities

categories.utils.compose(*fs) → Callable[source]

Return a function that is the composition of the functions in fs. All functions in fs must take a single argument.

Adapted from this StackOverflow answer: https://stackoverflow.com/a/34713317

Example:
>>> compose(f, g)(x) == f(g(x))
categories.utils.flip(f: Callable[[A, B], Any]) → Callable[[B, A], Any][source]

Return a function that reverses the arguments it’s called with.

Parameters:

f – A function that takes exactly two arguments

Example:
>>> exp = lambda x, y: x ** y
>>> flip_exp = flip(exp)
>>> exp(2, 3)
8
>>> flip_exp(2, 3)
9
categories.utils.unit(x: Any) → Any

The identity function. Returns whatever argument it’s called with.