Functions -
lang.array
enumerate | Returns a new array comprising of position and member pairs. |
filter | Returns a new array constructed from those elements of 'arr' for which |
forEach | Apply function |
fromBase16 | Returns the byte array that |
fromBase64 | Returns the byte array that |
indexOf | Returns the index of first member of |
iterator | Returns an iterator over the members of |
length | Returns the number of members contained in |
map | Returns a new array applying function |
pop | Remove and return the last member of the |
push | Add |
reduce | Reduce operate on each member of |
remove | Removes the member of |
removeAll | Removes all members of |
reverse | Reverse the order of the members of |
setLength | Increase or decrease the length.
|
shift | Remove and return first element of the array |
slice | Returns a sub array starting from |
sort | Sort |
toBase16 | Returns the string representing |
toBase64 | Returns the string representing |
unshift | Add |
Returns a new array comprising of position and member pairs.
Parameters
- arr Type[]
-
the array
Returns a new array constructed from those elements of 'arr' for which func
returns true.
Parameters
- arr Type[]
-
the array
-
Return Type
(Type[]) new array only containig members which evaluate function 'func' to true
Apply function func
to each member of array arr
.
Returns the byte array that str
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
Returns the byte array that str
represents in Base64 encoding.
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
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 the members of arr
Parameters
- arr Type[]
-
the array
-
Return Type
($anonType$2) iterator object
Returns the number of members contained in arr
.
-
Return Type
(int) number of members in the array
Returns a new array applying function func
to each member of array arr
.
Parameters
- arr Type[]
-
the array
-
Return Type
(Type1[]) new array containing result of applying function
func
to each member
Remove and return the last member of the arr
.
Parameters
- arr Type[]
-
the array
-
Return Type
(Type) removed member
Add vals
to end of the arr
array.
Reduce operate on each member of arr
using combining function func
to produce
a new value combining all members of arr
.
Parameters
- arr Type[]
-
the array
- initial Type1
-
initial value to first evaluation of combining function
func
-
Return Type
(Type1) result of applying combining function to each member of the array
Example: Emulating sum function.
var ar = [1, 2, 3]; var a = ar.reduce(function (int i, int j) returns int { return i + j; }, 0);
Example: Emulating map behavior.
var ar = [1, 2, 3]; int[] newArr = []; int[] a = ar.reduce(function (int[] a, int j) returns int[] { a.push(j*2); return a; }, newArr);
Removes the member of arr
and index i
and returns it.
Panics if i
is out of range.
-
Return Type
(Type) removed member
Removes all members of arr
.
Panics if any member cannot be removed.
Reverse the order of the members of arr
.
Returns arr
.
Parameters
- arr Type[]
-
the array to be reversed
-
Return Type
(Type[]) reversed
arr
Increase or decrease the length.
setLength(arr, 0)
is equivalent to removeAll(arr)
.
Remove and return first element of the array arr
.
Parameters
- arr Type[]
-
the array
-
Return Type
(Type) removed member
Returns a sub array 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
-
index of first member not to include in the slice
-
Return Type
(Type[]) array slice within specified range
Sort arr
using func
to order members.
Returns arr
.
-
Return Type
(Type[]) sorted
arr
Returns the string representing arr
using Base16.
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 representing arr
using Base64 encoding.
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