LibLinq-1.0

API / Enumerable

Enumerable.IsEnumerable(obj)

Return whether the provided object is an Enumerable

Parameters

obj
the object to check

Return value

whether the object inherits from or is an Enumerable


Enumerable.New(get_enumerator, enumerator_creator)

Construct and return a new Enumerable

Parameters

get_enumerator
enumerator_creator
a function that will return an enumerator that will be called when :GetEnumerator() is called.

Return value

The new Enumerable


Enumerable.prototype:GetEnumerator()

Return the enumerator for the current Enumerable

Return value

an Enumerator


Enumerable.prototype:Iterate()

Return a lua iterator that returns the index and value of each element and can be used in for loops.
If the loop is not fully iterated through, some garbage may persist improperly.

Usage

for index, value in Enumerable.From({ 1, 2, 3 }):Iterate() do end


Enumerable.prototype:StringJoin(separator, selector)

Concatenate the values of the enumerable into a single string

Parameters

separator
optional: the separator to use, defaults to an empty string
selector
optional: a function to select over the enumerable

Return value

a string

Usage

Enumerable.From({ 1, 2, 3 }):StringJoin() == "123"
Enumerable.From({ 1, 2, 3 }):StringJoin(", ") == "1, 2, 3"
Enumerable.From({ 1, 2, 3 }):StringJoin(", ", function(x) return x*x end) == "1, 4, 9"
Enumerable.From({ 1, 2, 3 }):StringJoin(", ", "x => x*x") == "1, 4, 9"


Enumerable.prototype:ToString()

Return a string representation of this Enumerable.
This should only show the first 10 elements of the Enumerable, after which it follows with an ellipsis (...).

Return value

a string


Enumerable.prototype:ToTable(kind)

Convert the enumerable to a simple lua table.
The implementation can vary the result, a list might return a numerically indexed table, whereas a set might return a table with all values as true. A dictionary will probably return a standard dictionary-style table. Not all values may show up in the table, especially in cases where nil is involved.

Parameters

kind
Either nil (to use the implementation's discretion), "list" to return a list-like table, or "set" to return a table where all values are true.

Return value

a lua table

Usage

Enumerable.From({ 'a', 'b', 'c' }):ToTable()[2] == 'b'
Enumerable.From({ 'a', 'b', 'c' }):ToTable('list')[2] == 'b'
Enumerable.From({ 'a', 'b', 'c' }):ToTable('set')['b'] == true


Enumerable.prototype:Unpack()

Unpack the contents of the enumerable to a lua argument tuple

Return value

zero or more values

Usage

a, b, c = Enumerable.From({ 1, 2, 3 }):Unpack()


Enumerable.prototype:WhereNotNil()

Return all non-nil elements

Return value

an Enumerable


You must login to post a comment. Don't have an account? Register to get one!