galactic.algebras.collection.core#

Defines some protocols for collections.

Protocols


class ExtensibleCollection(*args, **kwargs)#

Bases: Collection[_E], Protocol

Represents 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.

Parameters:

iterable (Iterable[TypeVar(_E)]) – An iterable of elements to add to the collection

Raises:

NotImplementedError –

Return type:

None

class MutableCollection(*args, **kwargs)#

Bases: ExtensibleCollection[_E], Protocol

Represents 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:

NotImplementedError –

Return type:

None

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:

NotImplementedError –

Return type:

None

abstractmethod discard(elem)#

Discard an element from the collection.

Parameters:

elem (TypeVar(_E)) – The element to discard

Raises:

NotImplementedError –

Return type:

None

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:

NotImplementedError –

abstractmethod clear()#

Remove all elements from the collection.

Raises:

NotImplementedError –

Return type:

None