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.
|
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
arr that is equal to val if there is one.
|
iterator |
Returns an iterator over an array.
|
lastIndexOf |
Returns the index of last member of
arr that is equal to val if there is one.
|
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.
|
push |
Adds values to the end of an array.
|
reduce |
Combines the members of an array using a combining function.
|
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.
|
slice |
Returns a subarray starting from
startIndex (inclusive) to endIndex (exclusive).
|
sort |
Sorts an array using a comparator function.
|
toBase16 |
Returns the string that is the Base16 representation of an array of bytes.
|
toBase64 |
Returns the string that is the Base64 representation of an array of bytes.
|
toStream |
Returns a stream from the given array.
|
unshift |
Adds values to the start of an array.
|
Parameters
- arr Type[]
-
the array
-
Return Type
([int, Type][]) array of index, member pairs
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
func
is applied to each member of array arr
in order.
Parameters
- arr Type[]
-
the array
-
func
function(Type) returns (())
-
a function to apply to each member
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
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
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 (default 0)
-
index to start the search from
-
Return Type
(int?) index of the member if found, else
()
Parameters
- arr Type[]
-
the array
-
Return Type
(T1) a new iterator object that will iterate over the members of
arr
.
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 (default <int> arr.length(arr) - 1)
-
index to start searching backwards from
-
Return Type
(int?) index of the member if found, else
()
Parameters
- arr any | error[]
-
the array
-
Return Type
(int) number of members in
arr
Parameters
- arr Type[]
-
the array
-
func
function(Type) returns (Type1)
-
a function to apply to each member
-
Return Type
(Type1[]) new array containing result of applying
func
to each member ofarr
in order
Parameters
- arr Type[]
-
the array
-
Return Type
(Type) removed member
Parameters
- arr Type[]
-
the array
- vals Type[]
-
values to add to the end of the array
Parameters
- arr Type[]
-
the array
-
func
function(Type1, Type) returns (Type1)
-
combining function
- initial Type1
-
initial value for the first argument of combining parameter
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)
.
Parameters
- arr Type[]
-
the array
- index int
-
index of member to be removed from
arr
-
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.
Parameters
- arr any | error[]
-
the array Panics if any member cannot be removed.
Parameters
- arr Type[]
-
the array to be reversed
-
Return Type
(Type[]) arr
with its members in reverse order
Parameters
- arr any | error[]
-
the array of which to change the length
- length int
-
new length
setLength(arr, 0)
is equivalent toremoveAll(arr)
.
Parameters
- arr Type[]
-
the array
-
Return Type
(Type) the value that was the first member of the array
startIndex
(inclusive) to endIndex
(exclusive).
Parameters
- arr Type[]
-
the array
- startIndex int
-
index of first member to include in the slice
- endIndex int (default <int> arr.length(arr))
-
index of first member not to include in the slice
-
Return Type
(Type[]) array slice within specified range
Parameters
- arr Type[]
-
the array to be sorted
-
func
function(Type, Type) returns (int)
-
comparator function
-
Return Type
(Type[]) arr
with its members sorted
0..9
, a..f
.
There will be no whitespace in the returned string.
Parameters
- arr byte[]
-
the array
-
Return Type
(string) Base16 string representation
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
Parameters
- arr Type[]
-
The array from which the stream is created
-
Return Type
(stream) The stream representation of the array
arr