Skip to content
SinisterRectus edited this page Feb 7, 2022 · 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.

This method only operates on data in memory.

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.

This method only operates on data in memory.

Returns: function


count(fn)

Parameter Type Optional
fn function

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

This method only operates on data in memory.

Returns: number


find(fn)

Parameter Type
fn function

Returns the first object that satisfies a predicate.

This method only operates on data in memory.

Returns: *


findAll(fn)

Parameter Type
fn function

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

This method only operates on data in memory.

Returns: function


forEach(fn)

Parameter Type
fn function

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

This method only operates on data in memory.

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.

This method only operates on data in memory.

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.

This method only operates on data in memory.

Returns: function


random()

Returns a random object that is contained in the iterable.

This method only operates on data in memory.

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.

This method only operates on data in memory.

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.

This method only operates on data in memory.

Returns: table


Methods

iter()

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

This method only operates on data in memory.

Returns: function


Clone this wiki locally