Collections - List


A list is an ordered collection of elements that are distinguished by their indices. List is ordered in the sense, it will retain the exact order in which elements are added to it. A list in 'Deluge' can contain values of different types say number, text, date, boolean etc. You can also force the list to accept only specific type of values using special qualifiers. In general, a list provides methods to store, retrieve and manipulate aggregate data. The following table is a visual representation of a list of Strings:

Index 0Index 1Index 2Index 3
"IPhone 3""IPhone 4""IPhone 4s""IPhone 5"

The index position of the first element in a list is always 0. To declare a list, use the List keyword followed by datatype, for example,

//creates an empty list of type Date, with name "dobList"
dobList = List:Date();

To access the elements in a list use the list methods supported by Deluge.


//creates a list of type date
dobList = List:Date();
//adds elements to the list
// Removes all elements from the dobList

Built in functions

Functions that operate on List expression are classified as List functions. They include functions for returning a boolean value if a condition is satisfied, returning the list size, returning the element at the specified position etc. Refer the topic Built-in-functions - List for the complete list of List functions.

colors = {"Red", "Blue", "Green", "Yellow"};
x = colors.size();
// the variable x returns 4

Share this post : FacebookTwitter