Functions - lang.table

add

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.

filter

Selects the members from a table for which a function returns true.

forEach

Applies a function to each member of a table. The func is applied to each member of t.

get

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.

hasKey

Tests whether t has a member with key k.

iterator

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.

keys

Returns a list of all the keys of table t.

length

Returns number of members of a table.

map

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.

nextKey

Returns the next available integer key.

put

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.

reduce

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.

remove

Removes a member of a table.

removeAll

Removes all members of a table. This panics if any member cannot be removed.

removeIfHasKey

Removes a member of a table with a given key, if the table has member with the key.

toArray

Returns a list of all the members of a table.

add

(table t, Type val)

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

filter

(table t, function(Type) returns (boolean) func)

returns table

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

forEach

(table t, function(Type) returns (()) func)

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

get

(table t, null k)

returns Type

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

hasKey

(table t, null k)

returns boolean

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 key k

iterator

(table t)

returns T2

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

    (T2)
  • a new iterator object that will iterate over the members of t

keys

(table t)

returns null[]

Returns a list of all the keys of table t.

Parameters

  • t table
  • the table

  • Return Type

    (null[])
  • a new list of all keys

length

(table t)

returns int

Returns number of members of a table.

Parameters

  • t table
  • the table

  • Return Type

    (int)
  • number of members in t

map

(table t, function(Type) returns (Type1) func)

returns table

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

nextKey

(table t)

returns int

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

put

(table t, Type val)

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

reduce

(table t, function(Type1, Type) returns (Type1) func, Type1 initial)

returns Type1

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 using func

remove

(table t, null k)

returns Type

Removes a member of a table.

Parameters

  • t table
  • the table

  • k null
  • the key

  • Return Type

    (Type)
  • the member of t that had key k This removed the member of t with key k and returns it. It panics if there is no such member.

removeAll

(table t)

Removes all members of a table. This panics if any member cannot be removed.

Parameters

  • t table
  • the table

removeIfHasKey

(table t, null k)

returns Type?

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 key k, or () if t does not have a key k If t has a member with key k, it removes and returns it; otherwise it returns ().

toArray

(table t)

returns Type[]

Returns a list of all the members of a table.

Parameters

  • t table
  • the table

  • Return Type

    (Type[])
  • an array whose members are the members of t