galactic.algebras.collection.core#
Defines some protocols for collections.
Protocols
- class ExtensibleCollection(*args, **kwargs)#
Bases:
Collection[_E],ProtocolRepresents an extensible collection.
An extensible collection is a collection that can be extended with additional elements from an iterable. This is useful for collections that need to maintain algebraic properties or consistency when new elements are added.
- abstractmethod extend(iterable)#
Extend the collection by adding the elements of the iterable.
Additional elements may be added by this method to preserve the algebraic consistency of the underlying structures.
- class MutableCollection(*args, **kwargs)#
Bases:
ExtensibleCollection[_E],ProtocolRepresents a mutable collection.
A mutable collection is a collection that allows adding, removing, and discarding elements, as well as clearing the collection. It is expected to support basic collection operations such as adding, removing, and checking membership of elements.
- abstractmethod add(elem)#
Add an element to the collection.
- Parameters:
elem (
TypeVar(_E)) – The element to add- Raises:
- Return type:
- abstractmethod remove(elem)#
Remove an element from the collection.
May raise a KeyError if the element is not present in the collection.
- Parameters:
elem (
TypeVar(_E)) – The element to remove- Raises:
- Return type:
- abstractmethod discard(elem)#
Discard an element from the collection.
- Parameters:
elem (
TypeVar(_E)) – The element to discard- Raises:
- Return type:
- abstractmethod pop()#
Remove and return an arbitrary element from the collection.
May raise a KeyError if the collection is empty.
- Returns:
The removed element
- Return type:
TypeVar(_E)- Raises:
- abstractmethod clear()#
Remove all elements from the collection.
- Raises:
- Return type: