Libraries anvil lang sequence

class sequence
extends anvil.lang.object
Sequence represents list of elements, that may be accessed with index. Some of sequences (such as string and tuple) are immutable and mutating operations always return copy of original sequence modified.

Methods

sequence append(object element)
Appends given element to this sequence.
Parameters element -  Element to append
Returns Modified sequence, original or copy

sequence clear()
Clears this sequence.
Returns Modified sequence, original or copy

sequence concat(sequence elements)
sequence concat(object element)
Concatenates given elements to this sequence.
Parameters element -  Element to concatenate
elements -  Elements of compatible sequence are concatenated
Returns Modified sequence, original or copy

int count(object element)
Count the number of elements which equals to given element.
Parameters element -  Element to count
Returns Number of elements mathinc given element

sequence crop(int start)
sequence crop(int start, int length)
Crops (shortens) this sequence to contain only specified range.
Parameters start -  Start of sub sequence
length -  Length of sub sequence
Returns Cropped sequence, original or copy

sequence cut(int start)
sequence cut(int start, int length)
Remove given range from sequence.
Parameters start -  Start of sub sequence to remove
length -  Length of sub sequence to remove
Returns Modified sequence, original or copy

boolean endsWith(object suffix)
boolean endsWith(sequence suffix)
Checks if sequence ends with given element or sequence

fill()
fill(object element)
fill(object element, int start)
fill(object element, int start, int length)
Fills sequence with given element.
Parameters element -  Element to fill with, default is null.
start -  Start of sub sequence to fill
start -  Length of sub sequence to fill
Returns Modified sequence, original or copy

any first()
any first(int index)
Returns first element from sequence, or undefined.
Parameters index -  Index to sequence, from beginning
Returns Element from sequence

object get(index1, index2, ...)
Fetches value from multi dimensional sequence. (i.e. sequence containing nested sequences). If missing index is encountered undefined is returned.

sequence grep(pattern pattern)
sequence grep(string pattern)
Returns new sequence of a same type as this, containing all elements that matched given regular expression.
Parameters pattern -  Regular expression to match with
Returns New sequence containing selected elements

int indexOf(object needle)
int indexOf(object needle, int fromIndex)
Finds the first index of given needle.
Parameters needle -  Element to search for
fromIndex -  Start index of search
Returns Index of needle, -1 if it wasn't found.

sequence insert(int start, sequence elements)
sequence insert(int start, object element)
sequence insert(int start, int length, sequence elements)
sequence insert(int start, int length, object element)
Inserts given element (or elements) to this sequence. Some elements might be replaced if length > 0.
Parameters start -  Insertion position
length -  Length of sub sequence to overwrite
element -  Element to insert
elements -  Elements of compatible sequence are inserted
Returns Modified sequence, original or copy

string join()
string join(clue)
Joins the string represtation of elements of this sequence together with given clue (default is de", ");
Parameters clue -  Clue to join elements with

any last()
any last(int index)
Returns last element from sequence, or undefined.
Parameters index -  Index to sequence, starting from end
Returns Element from sequence

int lastIndexOf(object needle)
int lastIndexOf(object needle, int fromIndex)
Finds the last index of given needle. Searching occurs from end to beginning.
Parameters needle -  Element to search for
fromIndex -  Start index of search
Returns Index or needle, -1 if it wasn't found.

int length()
Returns the length of this sequence.

tuple minmax()
Finds and returns minimum and maximum value from this sequence.
Returns tuple containing (minElement, maxElement)

object pop()
Pops last element out of this sequence
object pop(int index)
Pops element at given index out of this sequence
Parameters index -  Index of element
Returns Removed element

sequence push(object element, ...)
Adds given elements to end this sequence. Adding occurs in the same order as in parameter list, i.e. last parameter will be last in sequence.
Returns Modified sequence, original or copy

sequence repeat(int count)
Repeats this sequence given times.
Parameters count -  Number of times to repeat this sequence
Returns New sequence containing this sequence count times

sequence resize(int length)
Expands or contracts sequence to given length. If length is greater than current size, null is used as a fill.
Returns Modified sequence, original or copy

sequence reverse()
sequence reverse(int start)
sequence reverse(int start, int length)
Reverse elements in given range.
Parameters start -  Start index of sub sequence to reverse
length -  Length of sub sequence to reverse
Returns Reversed sequence, original or copy

int search(object element)
int search(object element, Function comparator)
Performs binary-search this sequence.
Parameters comparator -  Comparator function: function comparator(elem1, elem2). return less than 0 if elem1elem2.
element -  Element to search for
Returns Index of element found, or less than 0 if no element could be found.

object set(index1, index2, ..., value)
Sets value at given multi-dimensional sequence (i.e. sequence containing nested sequences). If missing index is encountered sequences remain unchanged.
Parameters value -  Value to set
Returns value

object shift()
Shifts (removes and returns) the first element out this sequence.
Returns First element of sequence, or undefined if sequence was empty.

sequence slice(int start)
sequence slice(int start, int length)
Takes slice from sequence.
Parameters start -  Start of sub sequence
length -  Length of sub sequence
Returns Sub sequence

sequence sort()
sequence sort(int start)
sequence sort(int start, int length)
sequence sort(int start, int length, Function comparator)
Sorts this sequence.
Parameters start -  Start of sub sequence to sort
start -  Lenght of sub sequence to sort
comparator -  Comparator function function comparator(elem1, elem2). Function should return less than 0 if elem1<elem2, 0 if elem1==elem2 or more than 0 if elem1>elem2.
Returns Sorted sequence, original or copy

boolean startsWith(object prefix)
boolean startsWith(sequence prefix)
Checks if sequence starts with given element or sequence

sequence swap(int index1, int index2)
Swaps elements of given indices.
Returns Modified sequence, original or copy

sequence unshift(object element, ...)
Insert given elements to this start sequence. Insertion happens in the same order as they appear in parameter list, i.e. last parameter will be first in sequence.
Returns Modified sequence, original or copy


Attributes

int this.length
Length of this sequence


References

object this[int index]
Returns element at given index
sequence this[int start..int end]
Returns sequence from given range
sequence this[indices...]
Returns sequence of elements
object this[int index] = element
Sets the element at given index
object this[int start .. int end] = element
Sets the content of sub sequence
object this[int start .. int end] = sequence
Sets the content of sub sequence
Parameters index -  Index of element
start -  Start of range (included)
end -  End of range (excluded)
element -  Element to set
sequence -  Elements to set


Operators

int sizeof this
Length of this sequence

boolean (boolean)this
true if length of this sequence is greater than 0, false otherwise.

this[] = element
Appends element to end of this sequence
this[] = sequence
Appends elements of sequence to end of this sequence

delete this[int index]
Removes element at given index
delete this[int start..int end]
Removes given range
delete this[indices...]
Removes indicices and ranges
Parameters index -  Index of element
start -  Start of range (included)
end -  End of range (excluded)
index -  Index of element

element in this
Checks if given element is in this sequence
sequence in this
Checks if given sequence is a sub sequence in this sequence

iterator *this
Returns iterator of elements in this sequence