Composable#
- class discopy.cat.Composable[source]#
Bases:
ABC
,Generic
[T
]Abstract class implementing the syntactic sugar
>>
and<<
for forward and backward composition with some methodthen
.Example
>>> class List(list, Composable): ... 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 (Composable[T] | None) – The other composable object to compose sequentially.
others (Composable[T]) –
- Return type:
Composable[T]
- is_composable(other)[source]#
Whether two objects are composable, i.e. the codomain of the first is the domain of the second.
- Parameters:
other (Composable) – The other composable object.
- Return type:
bool
- is_parallel(other)[source]#
Whether two composable objects are parallel, i.e. they have the same domain and codomain.
- Parameters:
other (Composable) – The other composable object.
- Return type:
bool