Libraries anvil lang array

class array
extends anvil.lang.object
Array is collections of keys mapped to values. Array has capabilities of list as it also retains doubly linked list of its elements.

Constructor
array(object element, ...)
Constructs array. Same as builtin [elements, ...] constructor.
Parameters element -  If parameter is map, corresponding key and value are added instead of map.


Methods

array append(object value)
Append given value into this array.
Returns this array modified

map both(int index)
Returns mapping at given index.
Parameters index -  Index to array

array clear()
Removess all mappings from this array.
Returns this array cleared

array concat(array values)
array concat(map mapping)
array concat(object element)
Appends value or values of array into this array.
Returns this array modified

array crop(int start, int length)
Contract this array to containg only given range.
Parameters start -  Start index
length -  Length of range
Returns this array modified

array cut(int start, int length)
Removes given range from this array.
Parameters start -  Start index
length -  Length of range
Returns this array modified

map dequeue()
Removes and returns first key=>value from this array.

iterator elements()
Returns an iterator of values in this array.

array enqueue(object element)
array enqueue(object key, object element)
Adds given element to end of array.
Parameters element -  Element to add

array find(object value)
Finds and returns the key of first mapping whose value was equal to given parameter.
Parameters value -  Value to search for
Returns Key of matched mapping, or undefined.

array findAll(object value)
Finds and returns all mappings whose value was equal to given parameter.
Parameters value -  Value to search for
Returns Array containing matched mappings

map first()
Returns the first mapping in this array.

object firstKey()
Returns the key of first mapping in this array.

object firstValue()
Returns the value of first mapping in this array.

object get(object key1, ...)
Fetches value from multi dimensional array. (i.e. array containing nested arrays). If missing key is encountered undefined is returned.

object getDefault()
Gets the default value returned if non-existent key is acccessed.

list getElements()
Returns list of values in this array.

list getKeys()
Returns list of keys in this array.

array grep(pattern keyPattern)
array grep(string keyPattern)
array grep(pattern keyPattern, pattern valuePattern [, boolean matchBoth])
array grep(string keyPattern, string valuePattern [, boolean matchBoth] )
Returns new array containing all mappings whose key and/or value matched given regular expressions.
Parameters keyPattern -  Regular expression to match keys with
valuePattern -  Regular expression to match values with
matchBoth -  if true both key and value is required to match.
Returns New array containing selected mappings
Throws MalformedPattern -  If any of patterns where invalid

array grepKeys(pattern pattern)
array grepKeys(string pattern)
Returns new array containing all mappings whose key matched matched given regular expression.
Parameters pattern -  Regular expression to match with
Returns New array containing selected mappings
Throws MalformedPattern -  If pattern was invalid

array grepValues(pattern pattern)
array grepValues(string pattern)
Returns new array containing all mappings whose value matched matched given regular expression.
Parameters pattern -  Regular expression to match with
Returns New array containing selected mappings
Throws MalformedPattern -  If pattern was invalid

array insert(int start, array values)
array insert(int start, map mapping)
array insert(int start, object element)
array insert(int start, int length, array values)
array insert(int start, int length, map mapping)
array insert(int start, int length, object element)
Inserts the mapped values of given array into given range in this array.
Parameters values -  Values to insert
start -  Start index in this array
length -  Length of range to overwrite
Returns this array modified

array intersect(array set)
Removes mappings whose key does not appear in both this array and given set.
Parameters set -  Set of mappings
Returns this array modified

string join()
string join(string clue)
Joins the string representation of mapped values in this array together with given clue.
Parameters clue -  Separator between values

object key(int index)
Returns the mapped key at given index.
Parameters index -  Index to array

iterator keys()
Returns an iterator of keys in this array.

iterator keysAndElements()
Returns an iterator of keys and values in this array.

map last()
Returns the last mapping in this array.

object lastKey()
Returns the key of last mapping in this array.

object lastValue()
Returns the value of last mapping in this array.

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

tuple minmaxKeys()
Finds and returns minimum and maximum key from this array.
Returns tuple containing (minKey, maxKey)

map next(object ofKey)
Return the next mapping of mapping mapped with given key.

object nextKey(object ofKey)
Return the key of next mapping of mapping mapped with given key.

object nextValue(object ofKey)
Return the value of next mapping of mapping mapped with given key.

object pop()
Removes the last mapping from this array and returns the value mapped.

int pos(object key)
Return the index of mappping with given key.
Returns Index to array

map previous(object ofKey)
Return the previous mapping of mapping mapped with given key.

object previousKey(object ofKey)
Return the key of previous mapping of mapping mapped with given key.
Parameters ofKey -  Key to array

object previousValue(object ofKey)
Return the value of previous mapping of mapping mapped with given key.
Parameters ofKey -  Key to array

array push(map mapping, ...)
array push(object element, ...)
For each parameter, inserts the value or mapping into the end of this array.

array reverse()
Reverses to order of mappings in this array.
Returns this array reversed

iterator select(object selector)
Returns an iterator containing all mappings for which given function returned true.
Parameters selector -  Callable selector: function selector(key, value, index)
Returns New array containing selected elements.

object set(object key1, ..., object value)
Sets value at given multi-dimensional array (i.e. array containing nested array). If missing key is encountered arrays remain unchanged.
Returns value

array setDefault(object defaultValue)
Sets the default value that will be returned if non-existent key is acccessed.
Returns this array

object shift()
Removes the first mapping from this array and returns the value mapped.

int size()
Returns the number of elements in array
Returns Number of elements

int sizeOf()
Returns the number of elements in array
Returns Number of elements

array slice(int start, int length)
Return mappings from given range.
Parameters start -  Start index
length -  Length of range
Returns Mappings from given range

array sort(Function comparator)
Sorts this array.
Parameters comparator -  Comparator function function comparator(key1, elem1, key2, elem2), Function should return less than 0 if elem1<elem2, 0 if elem1==elem2 or more than 0 if elem1>elem2.
Returns this array sorted

array sortByKey()
array sortByKey(boolean asceding)
Sorts this array according to keys.
Returns this array sorted

array sortByValue()
array sortByValue(boolean asceding)
Sorts this array according to mapped values.
Returns this array sorted

array subtract(array set)
Subtract mappings with the same keys as in given set.
Parameters set -  Set of mappings.
Returns this array subtracted

array swap(object key1, object key2)
Swaps the values pointed by given keys.
Returns this array

array swapOrder(object key1, object key2)
Swaps order the mappings pointed by given keys.
Returns this array

array union(array set)
Merges the keys and values. Existing values in this array are not overridden.
Parameters set -  Array to merge with
Returns this array modified

array unshift(map mapping, ...)
array unshift(object value, ...)
For each parameter, inserts the value or mapping into the start of this array.
Parameters mapping -  Mapping to add
value -  Value to add
Returns this array modified

object value(int index)
Returns the mapped value at given index.
Parameters index -  Index to array


Operators

int sizeof self
Returns the number of elements in this array.

boolean (boolean)self
true if number of mappings in this array is greater than 0, false otherwise.

object this[object key]
Returns element at given key
array this[object start..object end]
Returns array from given range
array this[indices...]
Returns array of elements at given keys and ranges
Parameters key -  key to array
start -  start key of range (included)
end -  end key of range (included)

this[object key] = object
Sets the element at given index
this[object start..object end] = object
Sets the content of range
this[object start..object end] = array
Sets the content of range
Parameters key -  key to array
start -  start key of range (included)
end -  end key of range (included)

this[] = object
Appends element to end of this sequence
this[] = map
Appends mapping to end of this sequence

delete this[object key]
Removes element at given key
delete this[object start..object end]
Removes given range
delete this[indices...]
Removes keys and ranges
Parameters key -  key to array
start -  start key of range (included)
end -  end key of range (included)

object in this
Checks if given element is in this array
map in this
Checks if given mapping is in this array

Returns iterator of keys and elements in this array