Collections

The galactic.algebras.collection modules.

It defines some protocols for collections:

class ExtensibleCollection(*args, **kwargs)

Bases: Collection[_E], Protocol

It represents extensible collections.

abstract extend(iterable)

Extend the collection by adding the elements of the iterable.

Other elements can be added by the method in order to maintain the algebraic consistency of the structures involved.

Parameters:

iterable (Iterable[TypeVar(_E)]) – An iterable of values

Raises:

NotImplementedError

Return type:

None

class MutableCollection(*args, **kwargs)

Bases: ExtensibleCollection[_E], Protocol

It represents mutable collections.

abstract add(value)

Add a value to the collection.

Parameters:

value (TypeVar(_E)) – The value to add.

Raises:

NotImplementedError

Return type:

None

abstract remove(value)

Remove a value from the collection.

This method can raise a KeyError if the value does not belong to the collection.

Parameters:

value (TypeVar(_E)) – The value to remove.

Raises:

NotImplementedError

Return type:

None

abstract discard(value)

Discard a value from the collection.

Parameters:

value (TypeVar(_E)) – The value to discard.

Raises:

NotImplementedError

Return type:

None

abstract pop()

Remove and return an arbitrary element from the collection.

This method can raise a KeyError if the collection is empty.

Returns:

The value removed.

Return type:

_E

Raises:

NotImplementedError

abstract clear()

Clear the collection.

Raises:

NotImplementedError

Return type:

None

abstract extend(iterable)

Extend the collection by adding the elements of the iterable.

Other elements can be added by the method in order to maintain the algebraic consistency of the structures involved.

Parameters:

iterable (Iterable[TypeVar(_E)]) – An iterable of values

Raises:

NotImplementedError

Return type:

None