categories package¶
Submodules¶
categories.applicative module¶
-
categories.applicative.
composition_law
(u, v, w, type_form=None)[source]¶ - pure (.) <*> u <*> v <*> w == u <*> (v <*> w)
- where (<*>) = apply
-
categories.applicative.
homomorphism_law
(f, x, _type, type_form=None)[source]¶ - pure f <*> pure x == pure (f x)
- where (<*>) = apply
-
categories.applicative.
identity_law
(v, type_form=None)[source]¶ - pure id <*> v == v
- where (<*>) = apply
-
categories.applicative.
interchange_law
(u, y, type_form=None)[source]¶ - u <*> pure y == pure ($ y) <*> u
- where (<*>) = apply
-
categories.applicative.
pure
(x, _type, type_form=None)[source]¶ The optional type_form arg is an attempt to provide some more flexibility with the type that pure is required to cast to. For example, pure for the tuple Applicative instance needs to know the types of its elements so it can return the correct object:
pure(7, tuple, type_form=(str, int)) == (“”, 7)
categories.builtins module¶
categories.either module¶
-
categories.either.
either
(f: Callable, g: Callable, x: categories.either.Either) → categories.either.Either[source]¶ Given two functions and an Either object, call the first function on the value in the Either if it’s a Left value, otherwise call the second function on the value in the Either. Return the result of the function that’s called.
Parameters: - f – a function that accepts the type packed in
x
- g – a function that accepts the type packed in
x
- x – an Either object
Returns: Whatever the functions
f
org
return- f – a function that accepts the type packed in
categories.functor module¶
categories.instances module¶
-
categories.instances.
make_adder
(instances: Dict[Type[CT_co], categories.instances.Typeclass]) → Callable[[Type[CT_co], categories.instances.Typeclass], None][source]¶
categories.maybe module¶
-
categories.maybe.
maybe
(default: B, f: Callable, x: categories.maybe.Maybe[~A][A]) → B[source]¶ Given a default value, a function, and a Maybe object, return the default if the Maybe object is Nothing, otherwise call the function with the value in the Maybe object, call the function on it, and return the result.
Parameters: - default – This is the value that gets returned if
x
is Nothing - f – When x matches Just, this function is called on the value in x, and the result is returned
- x – a Maybe object
Returns: Whatever type
default
or the return type off
is- default – This is the value that gets returned if
categories.monad module¶
categories.monoid module¶
-
categories.monoid.
associativity_law
(x, y, z)[source]¶ - (x <> y) <> z = x <> (y <> z)
- where (<>) = mappend
categories.utils module¶
-
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.
id_
(x: Any) → Any[source]¶ The identity function. Returns whatever argument it’s called with.
-
categories.utils.
unit
(x: Any) → Any¶ The identity function. Returns whatever argument it’s called with.