Category#

class discopy.abc.Category[source]#

Bases: abc.ABC, Generic

A category is a Python class with methods dom, cod, id, then, together with an attribute ob for its objects.

This base class also implements syntactic sugar >> and << for forward and backward composition with the method then.

Example

>>> class List(list, Category):
...     ob, dom, cod = type(None), None, None
...     def then(self, other):
...         return self + other
>>> assert List([1, 2]) >> List([3]) == List([1, 2, 3])
>>> assert List([3]) << List([1, 2]) == List([1, 2, 3])
abstract then(other, *others)[source]#

Sequential composition, to be instantiated.

Parameters:
  • other (Optional[Category[T]]) – The other arrow to compose sequentially.

  • others (Category[T]) –

Return type:

Category[T]

is_composable(other)[source]#

Whether two arrows are composable, i.e. the codomain of the first is the domain of the second.

Parameters:

other (Category) – The other arrow.

Return type:

bool

is_parallel(other)[source]#

Whether two arrows are parallel, i.e. they have the same domain and codomain.

Parameters:

other (Category) – The other arrow.

Return type:

bool