Container Functions
Functions you can use with containers
append
Adds the second argument to the end of the list specified as the first argument. The function returns the modified list.
This function is an alias of the push
function.
If the given list is null
, the function fails with an error.
The variant version fails if the first argument is not a list.
Example 258. Usage of append
append(["a", "b", "d"], "c"); // returns list ["a", "b", "d", "c"]
See also: insert, pop, push
binarySearch
The binarySearch()
function searches a specified list for a specified object using the binary search algorithm.
The elements of the list must be comparable and the list must be sorted in ascending order. If it is not sorted, the results are undefined.
Returns the index of the search key (≥ 0) if it is contained in the list. Otherwise, returns a negative number defined as (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the list.
If the list contains multiple objects equal to the search key, there is no guarantee which one will be found.
The function fails if either of the arguments is null
or if <element type> is not comparable.
Example 259. Usage of binarySearch
binarySearch(["a", "b", "d"], "b")
returns 1
, because the index of "b"
is 1.
binarySearch(["a", "b", "d"], "c")
returns -3
, because "c"
would be inserted at position 2.
See also: containsValue
clear
Empties the given list or map.
If the given argument is null
, the function fails with an error.
Example 260. Usage of clear
See also: poll, pop, remove
containsAll
The containsAll()
function returns true
if the list specified as the first argument contains every element of the list specified as the second argument, i.e. the second list is a sublist of the first list.
If one of the given list has a null
reference, the function fails with an error.
Example 261. Usage of containsAll
The function containsAll([1, 3, 5], [3,5])
returns true
.
The function containsAll([1,3,5], [2,3,5])
returns false
.
See also: containsKey, containsValue
containsKey
Returns true
, if the specified map (or variant containing a map) contains a mapping for the specified key.
If the given map is null
, the function fails with an error.
Example 262. Usage of containsKey
See also: containsValue, findAllValues, getKeys
containsValue
The containsValue(map, value)
function returns true
if the specified map maps one or more keys to the specified value.
The containsValue(list, value)
function returns true
if the specified list contains the specified value.
The containsValue(variant, variant)
function works as one of the two functions above, depending on whether the first argument contains a list or a map.
If the first argument is null
, the function fails with an error.
Example 263. Usage of containsValue
See also: containsKey, findAllValues, getValues, binarySearch
copy
The copy()
function copies items from one list to another.
The function accepts two list arguments of the same data types. The function takes the second argument, adds it to the end of the first list and returns the new value of the list specified as the first argument.
If one of the given lists has a null reference, the function fails with an error.
Example 264. Usage of copy
There are two lists. The list s1 = ["a", "b"]
and the list s2 = ["c", "d"]
. The function copy(s1, s2)
returns ["a", "b", "c", "d"]
. The list s1
has been modified and contains values ["a", "b", "c", "d"]
.
The copy()
function accepts two map arguments of the same data type. The function takes the second argument, adds it to the end of the first map replacing existing key mappings and returns the new value of the map specified as the first argument.
If one of the given maps has a null
reference, the function fails with an error.
If some key exists in both maps, the result will contain value from the second one.
Example 265. Usage of copy Let us have following lines of code.
The field field1
contains {a=aa, b=bbb}
. The field field2
contains {c=cc, d=ddd}
. The field field3
contains {a=aa, b=bbb, c=cc, d=ddd}
. The field field4
contains {a=aa, b=bbb, c=cc, d=ddd}
. The function copy
copies values from the second argument (map2
) to the first argument (map1
). The field field5
contains {c=cc, d=ddd}
.
See also: append, insert, poll, push
findAllValues
Returns the list of all values associated with the specified key at any level of the structure specified as the first argument. Returns an empty list if nothing was found. The container can be of any data type, however if this object contains no map the result will be an empty list. If the key is a record or a byte array, the function fails with an error.
Example 266. Usage of findAllValues
See also: containsKey, containsValue, getKeys, getValues
getKeys
Returns the list of keys of the specified map.
The returned list is of the same type as the map’s keys.
If a given map is null
, the function fails with an error.
The variant version fails if the argument is not a map.
Example 267. Usage of getKeys
See also: containsKey, containsValue, findAllValues, getValues
getValues
Returns the values contained in the specified map as a list.
If the argument is an empty map, the function returns an empty list.
If the argument is null
, the function fails.
Example 268. Usage of getValues
See also: containsKey, findAllValues, getKeys, toMap
in
Returns true if the specified collection contains the specified element. If the collection is a map, returns true if the map contains the element as a key.
Example 269. Usage of in
Note that searching for an element in a large list may be slow in comparison with searching for a key in a map, because list elements need to be checked one by one. For lists and maps of a specific numeric type, e.g. list[number] or a map with keys of type number, the searched-for element is automatically converted to the target type if possible, e.g. integers are converted to numbers. For variant, there is no such automatic type conversion, the types must exactly match for the function to return true.
See also: containsValue, containsKey
insert
Inserts one or more elements into the list at the specified position, indexed from 0. Moves the element currently at that position (if any) and all subsequent elements to the right. Returns the modified list.
If the list given as the first argument is null
, the function fails with an error.
Example 270. Usage of insert
See also: isNull, push, remove
isEmpty(container)
Returns true if the specified list, map or string is empty.
If the argument is null
, the function fails with an error.
Example 271. Usage of isEmpty
See also: String function: isEmpty(string), poll, pop
length(container)
Returns the number of elements forming a given structured data type.
The argument can be one of following: string
, list
, map
, record
or variant
containing any of these types.
For maps the function returns the number of key-value pairs and for nested lists it returns the size of the top-level list.
If the argument is null
, the function returns 0
.
Example 272. Usage of length:
See also: String functions: length(string), Record functions: length(record)
poll
The poll()
function removes the first element from a given list and returns this element.
The list specified as the argument changes to this new value (without the removed first element).
If a given list has a null reference, the function fails with an error.
Example 273. Usage of poll
The function poll(["a", "d", "c"])
returns a
. The list given as argument contains ["d", "c"]
after the function call.
See also: append, insert, pop, remove
pop
The pop() function
removes the last element from a given list and returns this element.
The list specified as the argument changes to this new value (without the removed last element).
If a given list has a null
reference, the function fails with an error.
Example 274. Usage of pop
The function
pop(["a", "b", "c"])
returnsc
.The function
pop
modifies lists1
:
field1
on first output port contains ["a", "b", "c"]
.
field2
on second output port contains c
.
field3
on first output port contains ["a", "b"]
.
See also: append, isEmpty(container), poll, push, remove
push
Adds an element to the end of the specified list. Returns the modified list.
This function is an alias of the append
function.
If the given list is null
, the function fails with an error.
The variant version fails if the first argument is not a list.
Example 275. Usage of push
See also: append, insert, pop, remove
remove
The function removes:
from a given list (or variant containing a list) the element at the specified
position
and returns the removed element. The list specified as the first argument changes its value to the new one. List elements are indexed starting from 0.from a given map (or variant containing a map) the key/value pair identified by the
key
and returns the value.
If the given list or map is null, the function fails with an error.
Example 276. Usage of remove - list
Example 277. Usage of remove - map
See also: append, insert, pop, push
reverse(list)
Reverses the order of elements of the given list and returns the modified list.
If the argument is null
, the function fails with an error.
The variant version fails if the argument is not a list.
Example 278. Usage of reverse
See also: sort, String functions: reverse(string)
sort
The sort()
function sorts the elements of a given list in ascending order according to their values and returns such new value of the list specified as the first argument.
Null values are listed at the end of the list, if present.
If a given list has a null
reference, the function fails with an error.
Example 279. Usage of sort The function sort(["a", "e", "c"]) returns ["a", "c", "e"].
See also: reverse(list)
toMap
The function toMap(k[], v[])
converts a list of keys
and lists of values
to the map. The function toMap(k[], v)
converts a list of keys
and value
to the map.
The keys
is a list containing the keys of the returned map.
The values
is a list of values corresponding to the keys. If only one value
is defined, the value
corresponds to all keys in the returned map.
The data types of list of keys must correspond to the data type of key in the map, the data type(s) of value(s) must correspond to the data type of values in the map.
The length of the list of keys (keys
argument) must be equal to the length of list of the values (values
argument).
If the parameter keys
is null
, the function fails.
If the parameter values
is null
, the function toMap([],[])
fails.
If the parameter value is null
, the function toMap([],)
returns a map having null
for all keys.
Example 280. Usage of toMap
The map alphabet
has the value alpha
accessible under the key "a", bravo
accessible under the key "b"
, etc.
The function toMap()
in this example fails as the list of keys (abcKeys
) and the list of values (alphaValues
) are of the different size.
The function toMap()
fails in this example. The list of values cannot be null
.
The result
is an empty map. The second argument of the function is a single value; therefore, it can be null
.
The variable availability
contains {ProductA=available, ProductB=available, ProductC=available}
. All products are available.
The map result
has three values: {a=null, b=null, c=null}
.
The result
is an empty list.
See also: getKeys, getValues, record2map