Collections
Declaration and Assignment
A collection is declared using square brackets:
Declaring a new collection
Person [] plist;A collection can be populated by:
adding objects one at a time to an empty collection
calling a selector BIF to query data - see Querying Data for details
returning a subset from another collection - see
subsetfunction below
Assigning the result of the all selector to a new collection
Person [] plist = Person:all();
Collection Built-in Functions
These BIFs can be called on any variable that holds a collection instance.
BIF | Description | Example |
|---|---|---|
| Removes and returns the first element from the collection. |
|
| Removes and returns the last element from the collection. |
|
| Returns the current length (number of elements) in the list. |
|
| Returns the first element in the list (without removing it). |
|
| Returns the last element in the list (without removing it). |
|
| Adds an element to the back of a list. |
|
| Adds an element to the front of the list. |
|
| Returns an element in the specific location in the list. |
|
| Adds an element to the specified position in the list. |
|
| Removes the element at the specified position in the list. |
|
| Sorts the list in ascending order. |
|
| Sorts the list in descending order. |
|
| Removes all elements from the list. |
|
| Prompts Helium to send notifications to the users associated with the objects in the collection, if the object declaration was annotated with @Role (function also available on singular object instances). |
|
| Returns a subset of the items in the original collection as a new collection. Takes selector BIFs as parameter. See Querying Data for more on selector BIFs. |
|
Additional Mentions and References
Last few sections of Lesson 8 of the tutorial. Brief mention in Lesson 6.