list.eh

Ordered collection of elements. More...

use "list.eh"

Types

type List < Any;

Functions

def List.add(val: Any);
def List.addall(vals: Array);
def List.clear();
def List.filter(f: (Any): Bool): List;
def List.filterself(f: (Any): Bool);
def List.get(at: Int): Any;
def List.indexof(val: Any): Int;
def List.insert(at: Int, val: Any);
def List.insertall(at: Int, vals: Array);
def List.len(): Int;
def List.lindexof(val: Any): Int;
def List.map(f: (Any): Any): List;
def List.mapself(f: (Any): Any);
def List.range(from: Int, to: Int): List;
def List.reduce(f: (Any, Any): Any): Any;
def List.remove(at: Int);
def List.reverse(): List;
def List.set(at: Int, val: Any);
def List.sort(f: (Any, Any): Int): List;
def List.sortself(f: (Any, Any): Int);
def List.toarray(): Array;
def List.tostr(): String;
def new_list(): List;

Description

A List is an ordered collection of elements (also known as sequence). Like in array, elements of list are enumerated by integer index from 0 to len()-1, however size of list is not fixed and may increase if needed. Lists support the same syntax as arrays. This header also provides convenient functions to sort, map, filter and fold lists.
var list = new_list()
list.addall(["tar", "gate"])
list[0] = "s" + list[0]
println(list.tostr())

Type details

type List < Any;
Sequence of elements.

Function details

def new_list(): List;
Creates new empty list.

def List.len(): Int;
Returns the number of elements in this list.

def List.get(at: Int): Any;
Returns element at the specified position of this list.

def List.set(at: Int, val: Any);
Replaces the element at the specified position in this list with the given value.

def List.add(val: Any);
Adds new element to the end of this list. Length of list increases by one.

def List.addall(vals: Array);
Adds all elements from the specified array to the end of this list. Length of list increases by length of given array.

def List.insert(at: Int, val: Any);
Inserts element at the specified position of this list. Length of list increases by one.

def List.insertall(at: Int, vals: Array);
Inserts all elements from given array at the specified position of this list. Length of list increases by length of given array.

def List.remove(at: Int);
Removes element at the specified position of the list decreasing its length by one.

def List.clear();
Removes all elements from the list.

def List.range(from: Int, to: Int): List;
Creates new list containing elements in given range of this list.

def List.indexof(val: Any): Int;
Returns index of the first occurence of given value in this list. If list does not contain given value, returns -1.

def List.lindexof(val: Any): Int;
Returns index of the last occurence of given value in this list. If list does not contain given value, returns -1.

def List.filter(f: (Any): Bool): List;
Creates new list containing only elements from this list that match given condition.

def List.filterself(f: (Any): Bool);
Filters this list leaving only elements that match given condition.

def List.map(f: (Any): Any): List;
Creates new list with elements obtained by applying given mapping to elements of this list.

def List.mapself(f: (Any): Any);
Transforms elements of this list using given mapping.

def List.reduce(f: (Any, Any): Any): Any;
Returns value obtained by sequential applying of given mapping to the elements of this list. If this list has no elements (its size is 0), this function returns null. If the list contains only one value, that value is returned. Otherwise, function f is applied to the first two elements of the list. Then f is applied to the result and the third element and so on.

def List.sort(f: (Any, Any): Int): List;
Creates new list with elements from this list sorted by given criteria. The function given as argument should return 0 if its arguments are equal, value less then 0 if its first argument is less then second and value greater then 0 if its first argument is greater then second.

def List.sortself(f: (Any, Any): Int);
Sorts elements of this list using given criteria. The function given as argument should return 0 if its arguments are equal, value less then 0 if its first argument is less then second and value greater then 0 if its first argument is greater then second.

def List.reverse(): List;
Creates new list with elements from this list in reverse order.

def List.toarray(): Array;
Allocates new array and fills it with elements of this list.

def List.tostr(): String;
Returns text representation of this list. The returned string has the form
"[element1, element2, ...]".