Module jls.util.List
Represents a list.
The class functions could be used for Lua tables.
Class List
List:new ([...]) | Creates a new List. |
list:indexOf (value) | Returns the index where the value is found or 0 if not present. |
list:add (value[, ...]) | Adds a new element at the end of this list. |
list:remove (index) | Removes the element at the specified index. |
list:removeFirst (value) | Removes the first specified value from this list. |
list:removeLast (value) | Removes the last specified value from this list. |
list:removeAll (value) | Removes the specified value from this list. |
list:insert (index, value) | Inserts a new element to this list at the specified index. |
list:size () | Returns the size of this list. |
list:map (f) | Returns a list containing the result of the function called on each element. |
list:reduce (f[, value]) | Returns the last result of the function called on each element. |
list:join ([sep[, i[, j]]]) | Returns a string by concatenating all the values of the specified list. |
List.removeFirst (list, value) | Removes the first specified value from the specified list. |
List.removeLast (list, value) | Removes the last specified value from the specified list. |
List.removeAll (list, value) | Removes the specified value from the specified list. |
List.join (list[, sep[, i[, j]]]) | Returns a string by concatenating all the values of the specified list. |
List.map ([d], t, f) | Returns a table containing the result of the function called on each element of the source table. |
List.size (t[, withHoles[, useN]]) | Returns the number of elements in the list or -1 if the specified table is not a list. |
List.isList (t[, withHoles[, acceptEmpty]]) | Returns true when the specified table is a list. |
Class List
A List class.
- List:new ([...])
-
Creates a new List.
Parameters:
- ... The values to add to the list. (optional)
- list:indexOf (value)
-
Returns the index where the value is found or 0 if not present.
Parameters:
- value The element to look for.
Returns:
-
number
the index or 0 if not present.
- list:add (value[, ...])
-
Adds a new element at the end of this list.
Parameters:
- value The element to add at the end of this list.
- ... Additional values to add. (optional)
Returns:
-
jls.util.List
this list.
- list:remove (index)
-
Removes the element at the specified index.
Parameters:
- index integer The index of the element to remove.
Returns:
-
The value of the removed element.
- list:removeFirst (value)
-
Removes the first specified value from this list.
The matching values are found using equality (==)
Parameters:
- value The value to remove from the list.
Returns:
-
boolean
true if a value has been removed.
- list:removeLast (value)
-
Removes the last specified value from this list.
Parameters:
- value The value to remove from the list.
Returns:
-
boolean
true if a value has been removed.
- list:removeAll (value)
-
Removes the specified value from this list.
Parameters:
- value The value to remove from the list.
- list:insert (index, value)
-
Inserts a new element to this list at the specified index.
Parameters:
- index integer The index where to insert the element.
- value The element to insert to this list.
Returns:
-
jls.util.List
this list.
- list:size ()
-
Returns the size of this list.
Returns:
-
integer
the size of this list.
- list:map (f)
-
Returns a list containing the result of the function called on each element.
Parameters:
- f function The function to call on each element.
Returns:
-
jls.util.List
the new list.
- list:reduce (f[, value])
-
Returns the last result of the function called on each element.
Parameters:
- f function The function to call on each element. The function is called with the last result, element, index and the list.
- value The initial value. (optional)
Returns:
-
the last result of the function.
- list:join ([sep[, i[, j]]])
-
Returns a string by concatenating all the values of the specified list.
tostring() is used to get the string of a value.
Parameters:
- sep string An optional separator to add between values. (optional)
- i integer The index of the first value, default is 1. (optional)
- j integer The index of the last value, default is #list. (optional)
Returns:
-
string
a string with all values joined.
- List.removeFirst (list, value)
-
Removes the first specified value from the specified list.
Parameters:
- list table The list from which to remove the value.
- value The value to remove from the list.
Returns:
-
boolean
true if a value has been removed.
- List.removeLast (list, value)
-
Removes the last specified value from the specified list.
Parameters:
- list table The list from which to remove the value.
- value The value to remove from the list.
Returns:
-
boolean
true if a value has been removed.
- List.removeAll (list, value)
-
Removes the specified value from the specified list.
Parameters:
- list table The list from which to remove the value.
- value The value to remove from the list.
- List.join (list[, sep[, i[, j]]])
-
Returns a string by concatenating all the values of the specified list.
tostring() is used to get the string of a value.
Parameters:
- list table The list of values to concatenate.
- sep string An optional separator to add between values. (optional)
- i integer The index of the first value, default is 1. (optional)
- j integer The index of the last value, default is #list. (optional)
Returns:
-
string
a string with all values joined.
- List.map ([d], t, f)
-
Returns a table containing the result of the function called on each element of the source table.
Parameters:
- d table the destination table, if missing then a new table will be returned. (optional)
- t table the table containing the elements to map.
- f function the function to call on each element.
Returns:
-
table
the destination table.
- List.size (t[, withHoles[, useN]])
-
Returns the number of elements in the list or -1 if the specified table is not a list.
A list has continuous integer keys starting at 1.
Parameters:
- t table The table to get the size from.
- withHoles boolean true to indicate that the list may have holes. (optional)
- useN boolean true to accept the field "n" as the number of elements. (optional)
Returns:
-
number
the number of elements in the list or -1.
- List.isList (t[, withHoles[, acceptEmpty]])
-
Returns true when the specified table is a list.
A list has continuous integer keys starting at 1.
A list may have a field "n" giving the size of the list as an integer.
Parameters:
- t table The table to check.
- withHoles boolean true to indicate that the list may have holes. (optional)
- acceptEmpty boolean true to indicate that the list could be empty. (optional)
Returns:
- boolean true when the specified table is a list.
- number the number of elements in the list or -1.