Module list

A simple list that keeps the order in which the items are added to it.

It is a thin wrapper around a simple, number indexed table providing various convenience methods.

Functions

ACCEPT_NON_NIL (value) An accept function that only accepts non nil values.
ACCEPT_NON_EMPTY_STRING (value) An accept function that only accepts non empty string values.
List:new (...) Creates a new instance of List.
List:add (...) Adds the given items to the list.
List:add_list (...) Adds the given List to the list.
List:clear () Clears all entries from the list.
List:contains (item) Checks if this list contains the given item.
List:cull_duplicates (comparator) Culls/removes all duplicates from this list.
List:foreach (action) Iterates over all items in the list and invokes the given action on them.
List:get (index) Gets the item at the given index.
List:get_first (accept) Gets the first value in this List that is accepted by the given function.
List:get_last (accept) Gets the last value in this List that is accepted by the given function.
List:index (item, equals) Returns the index of the given item.
List:invoke (...) If the List contains functions, this invokes all items with the given parameters.
List:is_empty () Gets if this List is empty.
List:matching (condition) Returns a List with all items that match the given condition.
List:remove (...) Removes the given values from the list.
List:remove_index (...) Removes the given index from the list.
List:return_first (accept, ...) Invokes the contained functions and returns the first value that is accepted by the given function.
List:return_last (accept, ...) Invokes the contained functions and returns the last value that is accepted by the given function.
List:size () Gets the size of the list.
List:sort (comparator) Sorts this List.
List:sub_list (from, count) Gets a sub list starting from the given index and the given number of items.
List:to_table () Turns this list into a table, the return table will be a one indexed array, and can freely be modified as it is not the table used by this instance.


Functions

ACCEPT_NON_NIL (value)
An accept function that only accepts non nil values.

Parameters:

  • value The value that is checked.

Returns:

    true if the given value is not nil.
ACCEPT_NON_EMPTY_STRING (value)
An accept function that only accepts non empty string values.

Parameters:

  • value The value that is checked.

Returns:

    true if the given value is a not empty string value.
List:new (...)
Creates a new instance of List.

Parameters:

  • ... Optional. A list of values to add.

Returns:

    A new instance of List.
List:add (...)
Adds the given items to the list.

Parameters:

  • ... The items to add.
List:add_list (...)
Adds the given List to the list.

Parameters:

  • ... The Lists to add.
List:clear ()
Clears all entries from the list.
List:contains (item)
Checks if this list contains the given item.

Parameters:

  • item The item to search for.

Returns:

    true if this list contains the given item.
List:cull_duplicates (comparator)
Culls/removes all duplicates from this list.

Parameters:

  • comparator Optional. The comparator to be used. Accepts two values and returns true if they can be considered equal. Defaults to testing the identity.
List:foreach (action)
Iterates over all items in the list and invokes the given action on them.

Parameters:

  • action The function to invoke on the item, the first parameter will be the item itself, the second (optional) parameter is the index. The function can return true to stop iterating over the items.
List:get (index)
Gets the item at the given index. Returns nil if there is no item. Note that there is no different between "no item" and "nil is the item", in both cases nil is returned.

Parameters:

  • index The index of the item to get.

Returns:

    The item at the given index. nil if there is no item.
List:get_first (accept)
Gets the first value in this List that is accepted by the given function.

Parameters:

  • accept Optional. The function to accept values. Accepts the value and returns a boolean, true if the value is accepted. If nil the first value in the list will be returned.

Returns:

    The first accepted value, or if none was accepted, nil.
List:get_last (accept)
Gets the last value in this List that is accepted by the given function.

Parameters:

  • accept Optional. The function to accept values. Accepts the value and returns a boolean, true if the value is accepted. If nil the last value in the list will be returned.

Returns:

    The last accepted value, or if none was accepted, nil.
List:index (item, equals)
Returns the index of the given item.

Parameters:

  • item The item for which to get the index.
  • equals Optional. The equals function to use.

Returns:

    The index of the given item. -1 if this item is not in this list.
List:invoke (...)
If the List contains functions, this invokes all items with the given parameters.

Parameters:

  • ... The parameters to invoke the functions.
List:is_empty ()
Gets if this List is empty.

Returns:

    true if this List is empty.
List:matching (condition)
Returns a List with all items that match the given condition.

Parameters:

  • condition The condition, a function that accepts one parameter, the item, and returns a boolean.

Returns:

    The List of matching items.
List:remove (...)
Removes the given values from the list.

Parameters:

  • ... The values to remove.
List:remove_index (...)
Removes the given index from the list.

Parameters:

  • ... The index to remove.
List:return_first (accept, ...)
Invokes the contained functions and returns the first value that is accepted by the given function.

Parameters:

  • accept The function to accept values, takes the value and returns a boolean, true if the value is accepted.
  • ... Optional. The parameters to invoke the functions with.

Returns:

    The first accepted return value, nil if none was accepted.
List:return_last (accept, ...)
Invokes the contained functions and returns the last value that is accepted by the given function.

Parameters:

  • accept The function to accept values, takes the value and returns a boolean, true if the value is accepted.
  • ... Optional. The parameters to invoke the functions with.

Returns:

    The last accepted return value, nil if none was accepted.
List:size ()
Gets the size of the list.

Returns:

    The size of the list.
List:sort (comparator)
Sorts this List.

Parameters:

  • comparator Optional. The comparator to be used. Accepts two values and returns a boolean, true if the first is parameter is less than the second.
List:sub_list (from, count)
Gets a sub list starting from the given index and the given number of items.

Parameters:

  • from The starting index.
  • count The count of items to get.

Returns:

    A List containing the items starting by the given index. The List will be empty if the starting index is out of range, if there are not as many items as specified with count, all items that there are will be returned.
List:to_table ()
Turns this list into a table, the return table will be a one indexed array, and can freely be modified as it is not the table used by this instance. However the items in the returned table are not copies.

Returns:

    This list as table.
generated by LDoc 1.4.2