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. | Person p = plist.pop();
|
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. | int len = plist.length();
|
first | Returns the first element in the list (without removing it). | Car c = person.cars.first();
|
last | Returns the last element in the list (without removing it). | Car c = person.cars.last();
|
append | Adds an element to the back of a list. | person.cars.append(c);
|
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. | Person child = p.children.get(2);
|
add | Adds an element to the specified position in the list. | p.children.add(1, Person:new());
|
remove | Removes the element at the specified position in the list. | p.children.remove(2);
|
sortAsc | Sorts the list in ascending order. |
|
sortDesc | Sorts the list in descending order. | numbers.sortDesc();
|
clear | Removes all elements from the list. | p.cars.clear();
|
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). | plist.notify(“description.key”, “sms.content.key”, “email.subj.key”, “email.content.key”);
|
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(); Person[] subset = persons.select(equals(name, "A")); |