Collections
- Former user (Deleted)
- Former user (Deleted)
Owned by Former user (Deleted)
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
subset
function 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 |
---|---|---|
pop | Removes and returns the first element from the collection. |
|
drop | Removes and returns the last element from the collection. | Person p = plist.drop(); |
length | Returns the current length (number of elements) in the list. |
|
first | Returns the first element in the list (without removing it). |
|
last | Returns the last element in the list (without removing it). |
|
append | Adds an element to the back of a list. |
|
prepend | Adds an element to the front of the list. | person.cars.prepend(c); |
get | Returns an element in the specific location in the list. |
|
add | Adds an element to the specified position in the list. |
|
remove | Removes the element at the specified position in the list. |
|
sortAsc | Sorts the list in ascending order. |
|
sortDesc | Sorts the list in descending order. |
|
clear | Removes all elements from the list. |
|
notify | 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). |
|
select | 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. | Person[] persons = Person:all(); |
Additional Mentions and References
- Last few sections of Lesson 8 of the tutorial. Brief mention in Lesson 6.
- Quick Reference#CollectionBIFs