Functions -
lang.array
enumerate | Returns a new array consisting of index and member pairs. |
filter | Selects the members from an array for which a function returns true. |
forEach | Applies a function to each member of an array.
The function |
fromBase16 | Returns the byte array that a string represents in Base16.
|
fromBase64 | Returns the byte array that a string represents in Base64.
|
indexOf | Returns the index of first member of |
iterator | Returns an iterator over an array. |
length | Returns the number of members of an array. |
map | Applies a function to each member of an array and returns an array of the results. |
pop | Removes and returns the last member of an array. The array must not be empty. |
push | Adds values to the end of an array. |
reduce | Combines the members of an array using a combining function. The combining function takes the combined value so far and a member of the array, and returns a new combined value. |
remove | Removes a member of an array. |
removeAll | Removes all members of an array. |
reverse | Reverses the order of the members of an array. |
setLength | Changes the length of an array. |
shift | Removes and returns first member of an array. The array must not be empty. |
slice | Returns a subarray starting from |
sort | Sorts an array using a comparator function. The comparator function must return a value less than, equal to or greater than zero according as its first argument is to be ordered before, equal to or after its second argument. |
toBase16 | Returns the string that is the Base16 representation of an array of bytes.
The representation is the same as used by a Ballerina Base16Literal.
The result will contain only characters |
toBase64 | Returns the string that is the Base64 representation of an array of bytes.
The representation is the same as used by a Ballerina Base64Literal.
The result will contain only characters |
unshift | Adds values to the start of an array.
The values newly added to the array will be in the same order
as they are in |
Returns a new array consisting of index and member pairs.
Parameters
- arr Type[]
-
the array
-
Return Type
([int, Type]) array of index, member pairs
Selects the members from an array for which a function returns true.
Parameters
- arr Type[]
-
the array
- func
function(Type) returns (boolean)
-
a predicate to apply to each member to test whether it should be selected
-
Return Type
(Type[]) new array only containing members of
arr
for whichfunc
evaluates to true
Applies a function to each member of an array.
The function func
is applied to each member of array arr
in order.
Returns the byte array that a string represents in Base16.
str
must consist of the characters 0..9
, A..F
, a..f
and whitespace as allowed by a Ballerina Base16Literal.
Parameters
- str string
-
Base16 string representation
-
Return Type
(byte | error) the byte array or error
Returns the byte array that a string represents in Base64.
str
must consist of the characters A..Z
, a..z
, 0..9
, +
, /
, =
and whitespace as allowed by a Ballerina Base64Literal.
Parameters
- str string
-
Base64 string representation
-
Return Type
(byte | error) the byte array or error
Returns the index of first member of arr
that is equal to val
if there is one.
Returns ()
if not found
Equality is tested using ==
Parameters
- arr PureType[]
-
the array
- val PureType
-
member to search for
- startIndex int - 0
-
index to start the search from
-
Return Type
(int) index of the member if found, else
()
Returns an iterator over an array.
Parameters
- arr Type[]
-
the array
-
Return Type
($anonType$1) a new iterator object that will iterate over the members of
arr
.
Returns the number of members of an array.
Parameters
- arr any | error
-
the array
-
Return Type
(int) number of members in
arr
Applies a function to each member of an array and returns an array of the results.
Parameters
- arr Type[]
-
the array
-
Return Type
(Type1[]) new array containing result of applying
func
to each member ofarr
in order
Removes and returns the last member of an array. The array must not be empty.
Parameters
- arr Type[]
-
the array
-
Return Type
(Type) removed member
Adds values to the end of an array.
Combines the members of an array using a combining function. The combining function takes the combined value so far and a member of the array, and returns a new combined value.
Parameters
- arr Type[]
-
the array
- initial Type1
-
initial value for the first argument of combining function
func
-
Return Type
(Type1) result of combining the members of
arr
usingfunc
For example
reduce([1, 2, 3], function (int total, int n) returns int { return total + n; }, 0)
is the same as
sum(1, 2, 3)
.
Removes a member of an array.
-
Return Type
(Type) the member of
arr
that was atindex
This removes the member ofarr
with indexindex
and returns it. It panics if there is no such member.
Removes all members of an array.
Parameters
- arr any | error
-
the array Panics if any member cannot be removed.
Reverses the order of the members of an array.
Parameters
- arr Type[]
-
the array to be reversed
-
Return Type
(Type[]) arr
with its members in reverse order
Changes the length of an array.
Parameters
- arr any | error
-
the array of which to change the length
- length int
-
new length
setLength(arr, 0)
is equivalent toremoveAll(arr)
.
Removes and returns first member of an array. The array must not be empty.
Parameters
- arr Type[]
-
the array
-
Return Type
(Type) the value that was the first member of the array
Returns a subarray starting from startIndex
(inclusive) to endIndex
(exclusive).
Parameters
- arr Type[]
-
the array
- startIndex int
-
index of first member to include in the slice
- endIndex int - arr.length(arr)
-
index of first member not to include in the slice
-
Return Type
(Type[]) array slice within specified range
Sorts an array using a comparator function. The comparator function must return a value less than, equal to or greater than zero according as its first argument is to be ordered before, equal to or after its second argument.
Parameters
- arr Type[]
-
the array to be sorted
-
Return Type
(Type[]) arr
with its members sorted
Returns the string that is the Base16 representation of an array of bytes.
The representation is the same as used by a Ballerina Base16Literal.
The result will contain only characters 0..9
, a..f
.
There will be no whitespace in the returned string.
Parameters
- arr byte
-
the array
-
Return Type
(string) Base16 string representation
Returns the string that is the Base64 representation of an array of bytes.
The representation is the same as used by a Ballerina Base64Literal.
The result will contain only characters A..Z
, a..z
, 0..9
, +
, /
and =
.
There will be no whitespace in the returned string.
Parameters
- arr byte
-
the array
-
Return Type
(string) Base64 string representation