Skip to content
ConcordConcordConcord

List

Data structure that allows for fast removal at the cost of order.

If the concord folder is in the root directory of your game, you can import this module like so:

List = require('concord.list')

Creates a new List.

list = List.new()
Name Type Description
list List

Adds an object to the List.

Object must be of reference type Object may not be the string ‘size’, ‘onAdded’ or ‘onRemoved’

list = list:add( obj )
Name Type Description
obj any Object to add
Name Type Description
list List

Removes an object from the List.

list:remove( obj )
Name Type Description
obj any Object to remove
Name Type Description
List|nil Returns self if removed; nil if the object was not in the List

Clears the List completely.

Does not call onRemoved.

list = list:clear()
Name Type Description
list List

Returns true if the List has the object.

boolean = list:has( obj )
Name Type Description
obj any Object to check for
Name Type Description
boolean boolean

Returns the object at an index.

any = list:get( i )
Name Type Description
i integer Index to get from

Returns the index of an object in the List.

Errors if the object is not in the List.

integer = list:indexOf( obj )
Name Type Description
obj any Object to get index of
Name Type Description
integer integer index of object in the List.

Sorts the List in place, using the order function.

The order function is passed to table.sort internally so documentation on table.sort can be used as reference.

list = list:sort( order )
Name Type Description
order fun(a: any, b: any): boolean Function that takes two items (a and b) and returns true if a should go before b.
Name Type Description
list List

Callback for when an item is added to the List.

list:onAdded( obj )
Name Type Description
obj any Object that was added

Callback for when an item is removed from the List.

Not called by List:clear.

list:onRemoved( obj )
Name Type Description
obj any Object that was removed