Functions
-
lang.table
add |
I
Adds a member |
filter |
Selects the members from a table for which a function returns true. |
forEach |
Applies a function to each member of a table. |
get |
I
Returns the member of table |
hasKey |
I
Tests whether |
iterator |
I
Returns an iterator over a table. |
keys |
I
Returns a list of all the keys of table |
length |
I
Returns number of members of a table. |
map |
Applies a function each member of a table and returns a table of the result. |
nextKey |
I
Returns the next available integer key. |
put |
I
Adds a member |
reduce |
Combines the members of a table using a combining function. |
remove |
I
Removes a member of a table. |
removeAll |
I
Removes all members of a table. |
removeIfHasKey |
I
Removes a member of a table with a given key, if the table has member with the key. |
toArray |
I
Returns a list of all the members of a table. |
Adds a member val
to table t
.
It will be added as the last member.
It panics if val
has the same key as an existing member of t
,
or if val
is inconsistent with the inherent type of t
.
Parameters
- t table
-
the table
- val Type
-
the member
Selects the members from a table for which a function returns true.
Parameters
- t table
-
the table
-
func
function(Type) returns (boolean)
-
a predicate to apply to each member to test whether it should be included
-
Return Type
(table) new table containing members for which
func
evaluates to true
Applies a function to each member of a table.
The func
is applied to each member of t
.
Parameters
- t table
-
the table
-
func
function(Type) returns (())
-
a function to apply to each member
Returns the member of table t
with key k
.
This for use in a case where it is known that the table has a specific key,
and accordingly panics if t
does not have a member with key k
.
Parameters
- t table
-
the table
- k null
-
the key
-
Return Type
(Type) member with key
k
Tests whether t
has a member with key k
.
Parameters
- t table
-
the table
- k null
-
the key
-
Return Type
(boolean) true if
t
has a member with keyk
iterator
(table t)
returns object { public function next () returns (record {| (any|error) value; |}?); }Returns an iterator over a table.
The iterator will iterate over the members of the table not the keys.
The entries
function can be used to iterate over the keys and members together.
The keys
function can be used to iterator over just the keys.
Parameters
- t table
-
the table
-
Return Type
(object { public function next () returns (record {| (any|error) value; |}?); }) a new iterator object that will iterate over the members of
t
Returns a list of all the keys of table t
.
Parameters
- t table
-
the table
-
Return Type
(null[]) a new list of all keys
Returns number of members of a table.
Parameters
- t table
-
the table
-
Return Type
(int) number of members in
t
Applies a function each member of a table and returns a table of the result. The resulting table will have the same keys as the argument table.
Parameters
- t table
-
the table
-
func
function(Type) returns (Type1)
-
a function to apply to each member
-
Return Type
(table) new table containing result of applying
func
to each member
Returns the next available integer key.
Parameters
- t table
-
the table with a key of type int
-
Return Type
(int) an integer not yet used as a key This is maximum used key value + 1, or 0 if no key used XXX should it be 0, if the maximum used key value is < 0? Provides similar functionality to auto-increment
Adds a member val
to table t
, replacing any member with the same key value.
If val
replaces an existing member, it will have the same position
in the order of the members as the existing member;
otherwise, it will be added as the last member.
It panics if val
is inconsistent with the inherent type of t
.
Parameters
- t table
-
the table
- val Type
-
the member
Combines the members of a table using a combining function. The combining function takes the combined value so far and a member of the table, and returns a new combined value.
Parameters
- t table
-
the table
-
func
function(Type1, Type) returns (Type1)
-
combining function
- initial Type1
-
initial value for the first argument of combining
func
-
Return Type
(Type1) result of combining the members of
t
usingfunc
Removes a member of a table.
Parameters
- t table
-
the table
- k null
-
the key
-
Return Type
(Type) the member of
t
that had keyk
This removed the member oft
with keyk
and returns it. It panics if there is no such member.
Removes all members of a table. This panics if any member cannot be removed.
Parameters
- t table
-
the table
Removes a member of a table with a given key, if the table has member with the key.
Parameters
- t table
-
the table
- k null
-
the key
-
Return Type
(Type?) the member of
t
that had keyk
, or()
ift
does not have a keyk
Ift
has a member with keyk
, it removes and returns it; otherwise it returns()
.