Category#

class discopy.abc.Category[source]#

Bases: abc.ABC, Generic

A category is a class with two class variables ob, ar, two attributes dom, cod and two methods id, then.

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 classmethod id(dom)[source]#

Identity morphism on an object dom: C0, to be instantiated.

Parameters:

dom (C0) – The domain of an identity is also its codomain.

Return type:

C1

abstract then(*others)[source]#

Sequential composition of n >= 1 morphisms, to be instantiated.

Parameters:
  • other – The other morphism to compose sequentially.

  • others (C1) –

Return type:

C1

is_composable(other)[source]#

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

Parameters:

other (C1) – The other morphism.

Return type:

bool

is_parallel(other)[source]#

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

Parameters:

other (Category) – The other morphism.

Return type:

bool