API/Enumerable-Ordering
Enumerable.prototype:OrderBy(key_selector)
Sorts the elements of the sequence in ascending order according to a key
Parameters
- key_selector
- a function to get a key from an element
Return value
an OrderedEnumerable
Usage
Enumerable.From({ "alpha", "bravo", "charlie" }):OrderBy(function(x) return x:len() end)
Enumerable.From({ "alpha", "bravo", "charlie" }):OrderBy("x => x:len()")
Enumerable.prototype:OrderByDescending(key_selector)
Sorts the elements of the sequence in descending order according to a key
Parameters
- key_selector
- a function to get a key from an element
Return value
an OrderedEnumerable
Usage
Enumerable.From({ "alpha", "bravo", "charlie" }):OrderByDescending(function(x) return x:len() end)
Enumerable.From({ "alpha", "bravo", "charlie" }):OrderByDescending("x => x:len()")
Enumerable.prototype:Reverse()
Reverses the order of a sequence
Return value
an Enumerable
Usage
Enumerable.From({ 1, 2, 3, 4 }):Reverse():ToString() == "[4, 3, 2, 1]"
Enumerable.prototype:Shuffle()
Randomizes the order of a sequence
Return value
an Enumerable
Usage
Enumerable.From({ 1, 2, 3, 4 }):Shuffle():ToString() == "[3, 4, 1, 2]"
OrderedEnumerable.prototype:GetComparer()
Returns a compareer of the current enumerable, which provides can be called and returns the relative sort order of the two passed-in values.
Return value
a comparer
Usage
local comparer = Enumerable.From({ 1, 2, 3 }):OrderBy(function(x) return x end):GetComparer()
OrderedEnumerable.prototype:ThenBy(key_selector)
Adds a subsequent sort ordering the elements of the sequence in ascending order according to a key
Parameters
- key_selector
- a function to get a key from an element
Return value
an OrderedEnumerable
Usage
Enumerable.From({ "alpha", "bravo", "charlie" }):OrderBy(function(x) return x:len() end):ThenBy(function(x) return x end)
Enumerable.From({ "alpha", "bravo", "charlie" }):OrderBy("x => x:len()"):ThenBy("x => x")
OrderedEnumerable.prototype:ThenByDescending(key_selector)
Adds a subsequent sort ordering the elements of the sequence in descending order according to a key
Parameters
- key_selector
- a function to get a key from an element
Return value
an OrderedEnumerable
Usage
Enumerable.From({ "alpha", "bravo", "charlie" }):OrderBy(function(x) return x:len() end):ThenByDescending(function(x) return x end)
Enumerable.From({ "alpha", "bravo", "charlie" }):OrderBy("x => x:len()"):ThenByDescending("x => x")
Comments