📘 Collections

📘 Collections#

In this tutorial, we will explore the various collection types available in the GALACTIC framework. Collections are fundamental data structures that allow us to store and manipulate groups of elements.

We will cover the following collection types from the galactic.algebras.collection.core module:

  • ExtensibleCollection is a protocol for collections that can be extended with new elements. It defines a method for adding elements to the collection. The mechanism for adding elements is left to the specific implementation of the collection (i.e. other elements can be added to preserve algebraic properties). The extend() method is provided to add multiple elements at once.

  • MutableCollection is a protocol for collections that can be modified. It extends the ExtensibleCollection protocol and adds methods for removing elements from the collection:

    • add() method to add a specific element to the collection

    • remove() method to remove a specific element from the collection

    • discard() method to remove a specific element without raising an error if the element is not present

    • pop() method to remove and return an arbitrary element from the collection

    • clear() method to remove all elements from the collection