Skip to content
SinisterRectus edited this page Jun 24, 2019 · 5 revisions

extends Iterable

Iterable class that wraps a basic Lua table, where order is not guaranteed. Some versions may use a map function to shape the objects before they are accessed.

Instances of this class should not be constructed by users.

Methods Inherited From Iterable

__len()

Defines the behavior of the # operator. Returns the total number of objects stored in the iterable.

Returns: function

__pairs()

Defines the behavior of the pairs function. Returns an iterator that returns a key, value pair, where key is the result of calling __hash on the value.

Returns: function

count(fn)

Parameter Type Optional
fn function

If a predicate is provided, this returns the number of objects in the iterable that satistfy the predicate; otherwise, the total number of objects.

Returns: number

find(fn)

Parameter Type
fn function

Returns the first object that satisfies a predicate.

Returns: *

findAll(fn)

Parameter Type
fn function

Returns an iterator that returns all objects that satisfy a predicate.

Returns: function

forEach(fn)

Parameter Type
fn function

Iterates through all objects and calls a function fn that takes the objects as an argument.

Returns: nil

get(k)

Parameter Type
k *

Returns an individual object by key, where the key should match the result of calling __hash on the contained objects. Operates with up to O(n) complexity.

Returns: *

pick(...)

Parameter Type
... string/function

This returns an iterator that, when called, returns the values from each encountered object, picked by the provided keys. If a key is a string, the objects are indexed with the string. If a key is a function, the function is called with the object passed as its first argument.

Returns: function

random()

Returns a random object that is contained in the iterable.

Returns: *

select(...)

Parameter Type
... string

Similarly to an SQL query, this returns a sorted Lua table of rows where each row corresponds to each object in the iterable, and each value in the row is selected from the objects according to the keys provided.

Returns: table

toArray(sortBy, fn)

Parameter Type Optional
sortBy string
fn function

Returns a sequentially-indexed table that contains references to all objects. If a sortBy string is provided, then the table is sorted by that particular property. If a predicate is provided, then only objects that satisfy it will be included.

Returns: table

Methods

iter()

Returns an iterator that returns all contained objects. The order of the objects is not guaranteed.

Returns: function

Clone this wiki locally