Module:FunList/EnumerableExtensions/doc: Difference between revisions

From Melvor Idle
(Created page with "Contains all shorthand functions that convert one Enumerable object into another. Most of these functions can be chained together to result in a state machine that captures all of the applied functions. The state machine is only executed once a pairs or ipairs operator is applied to the state machine, or by manually progressing the Module:FunList/Enumerator.")
 
No edit summary
 
Line 1: Line 1:
Contains all shorthand functions that convert one Enumerable object into another. Most of these functions can be chained together to result in a state machine that captures all of the applied functions. The state machine is only executed once a pairs or ipairs operator is applied to the state machine, or by manually progressing the [[Module:FunList/Enumerator]].
Contains all shorthand functions that convert one Enumerable object into another. Most of these functions can be chained together to result in a state machine that captures all of the applied functions. The state machine is only executed once a pairs or ipairs operator is applied to the state machine, or by manually progressing the [[Module:FunList/Enumerator]].
<onlyinclude>
== Functions ==
=== all ===
<syntaxhighlight lang="lua">
-- Determines whether all elements of a sequence satisfy a condition.
---@param self Enumerable
---@param predicate fun(item: any): boolean
---@return boolean
function Enumerable:all(predicate)
</syntaxhighlight>
=== any ===
<syntaxhighlight lang="lua">
-- Determines whether any element of a sequence exists or satisfies a condition.
---@param self Enumerable
---@param predicate fun(item: any): boolean
---@return boolean
function Enumerable:any(predicate)
</syntaxhighlight>
=== append ===
<syntaxhighlight lang="lua">
-- Adds an item to the end of the enumerable.
---@param self Enumerable
---@param item any
function Enumerable:append(item)
</syntaxhighlight>
=== prepend ===
<syntaxhighlight lang="lua">
-- Adds an item to the front of the enumerable.
---@param self Enumerable
---@param item any
function Enumerable:prepend(item)
</syntaxhighlight>
=== contains ===
<syntaxhighlight lang="lua">
-- Determines whether a sequence contains a specified element.
---@param self Enumerable
---@param item any
---@return boolean
function Enumerable:contains(item)
</syntaxhighlight>
=== count ===
<syntaxhighlight lang="lua">
-- Returns the number of elements in a sequence.
---@param self Enumerable
---@return integer
function Enumerable:count()
</syntaxhighlight>
=== first ===
<syntaxhighlight lang="lua">
-- Returns the first element of a sequence.
---@param self Enumerable
---@param predicate? fun(item: any): boolean
---@return any
function Enumerable:first(predicate)
</syntaxhighlight>
=== firstOrDefault ===
<syntaxhighlight lang="lua">
-- Returns the first element of a sequence, or a default value if no element is found.
---@param self Enumerable
---@param predicate? fun(item: any): boolean
---@param defaultItem? any
---@return any
function Enumerable:firstOrDefault(predicate, defaultItem)
</syntaxhighlight>
=== last ===
<syntaxhighlight lang="lua">
-- Returns the last element of a sequence.
---@param self Enumerable
---@return any
function Enumerable:last()
</syntaxhighlight>
=== lastOrDefault ===
<syntaxhighlight lang="lua">
-- Returns the last element of a sequence, or a default value if no element is found.
---@param self Enumerable
---@param defaultItem? any
---@return any
function Enumerable:lastOrDefault(defaultItem)
</syntaxhighlight>
=== max ===
<syntaxhighlight lang="lua">
-- Returns the maximum value in a sequence of values.
---@param self Enumerable
---@return number
function Enumerable:max()
</syntaxhighlight>
=== min ===
<syntaxhighlight lang="lua">
-- Returns the minimum value in a sequence of values.
---@param self Enumerable
---@return number
function Enumerable:min()
</syntaxhighlight>
=== sum ===
<syntaxhighlight lang="lua">
-- Returns the sum value of a sequence of values.
function Enumerable:sum()
</syntaxhighlight>
=== concat ===
<syntaxhighlight lang="lua">
-- Adds elements from one sequence to the other.
---@param self Enumerable
---@param other Enumerable
function Enumerable:concat(other)
</syntaxhighlight>
=== difference ===
<syntaxhighlight lang="lua">
-- Gets the difference between two sequences
---@param self Enumerable
---@param other Enumerable
function Enumerable:difference(other)
</syntaxhighlight>
=== differenceBy ===
<syntaxhighlight lang="lua">
-- Gets the difference between two sequences based on a key
---@param self Enumerable
---@param keySelector? fun(value: any, index: any): any
function Enumerable:differenceBy(other, keySelector)
</syntaxhighlight>
=== flatMap ===
<syntaxhighlight lang="lua">
-- Maps items from one sequence to another.
---@param self Enumerable
---@param selector fun(value: any, index: integer): any
function Enumerable:flatMap(selector)
</syntaxhighlight>
=== groupBy ===
<syntaxhighlight lang="lua">
--Groups the elements of a sequence.
---@param self Enumerable
---@param keySelector fun(param: any): any
---@param elementSelector? fun(param: any): any
function Enumerable:groupBy(keySelector, elementSelector)
</syntaxhighlight>
=== groupByResult ===
<syntaxhighlight lang="lua">
--Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. The elements of each group are projected by using a specified function.
---@param self Enumerable
---@param keySelector fun(param: any): any
---@param elementSelector? fun(param: any): any
---@param resultSelector fun(key: any, grouping: Grouping): any
function Enumerable:groupByResult(keySelector, elementSelector, resultSelector)
</syntaxhighlight>
=== intersect ===
<syntaxhighlight lang="lua">
--Produces the set intersection of two sequences.
---@param self Enumerable
---@param other Enumerable
function Enumerable:intersect(other)
</syntaxhighlight>
=== intersectBy ===
<syntaxhighlight lang="lua">
--Produces the set intersection of two sequences according to a specified key selector function.
---@param self Enumerable
---@param other Enumerable
---@param keySelector? fun(value: any, index: any): any
function Enumerable:intersectBy(other, keySelector)
</syntaxhighlight>
=== map ===
<syntaxhighlight lang="lua">
--Projects each element of a sequence into a new form.
---@param self Enumerable
---@param selector fun(value: any, index: any): any
function Enumerable:map(selector)
</syntaxhighlight>
=== sort ===
<syntaxhighlight lang="lua">
--Sorts a sequence.
---@param self Enumerable
---@return SortableIterator
function Enumerable:sort()
</syntaxhighlight>
=== sortDescending ===
<syntaxhighlight lang="lua">
--Sorts a sequence in descending order.
---@param self Enumerable
---@return SortableIterator
function Enumerable:sortDescending()
</syntaxhighlight>
=== sortBy ===
<syntaxhighlight lang="lua">
--Sorts a sequence based on a specified key selector function.
---@param self Enumerable
---@return SortableIterator
function Enumerable:sortBy(keySelector)
</syntaxhighlight>
=== sortByDescending ===
<syntaxhighlight lang="lua">
--Sorts a sequence based on a specified key selector function in descending order.
---@param self Enumerable
---@return SortableIterator
function Enumerable:sortByDescending(keySelector)
</syntaxhighlight>
=== thenSortBy ===
<syntaxhighlight lang="lua">
--Sorts a sorted sequence further based on a specified key selector function.
---@param self SortableIterator
---@return SortableIterator
function Enumerable:thenSortBy(keySelector)
</syntaxhighlight>
=== thenSortByDescending ===
<syntaxhighlight lang="lua">
--Sorts a sorted sequence further based on a specified key selector function in descending order.
---@param self SortableIterator
---@return SortableIterator
function Enumerable:thenSortByDescending(keySelector)
</syntaxhighlight>
=== union ===
<syntaxhighlight lang="lua">
--Produces the set union of two sequences according to a specified key selector function.
---@param self Enumerable
---@param other any
function Enumerable:union(other)
</syntaxhighlight>
=== unionBy ===
<syntaxhighlight lang="lua">
--Produces the set union of two sequences according to a specified key selector function.
---@param self Enumerable
---@param other any
---@param keySelector? fun(value: any, index: any): any
function Enumerable:unionBy(other, keySelector)
</syntaxhighlight>
=== unique ===
<syntaxhighlight lang="lua">
--Returns unique (distinct) elements from a sequence according to a specified key selector function.
---@param self Enumerable
function Enumerable:unique()
</syntaxhighlight>
=== uniqueBy ===
<syntaxhighlight lang="lua">
--Returns unique (distinct) elements from a sequence according to a specified key selector function.
---@param self Enumerable
---@param keySelector? fun(value: any, index: any): any
function Enumerable:uniqueBy(keySelector)
</syntaxhighlight>
=== where ===
<syntaxhighlight lang="lua">
--Filters a sequence of values based on a predicate.
---@param self Enumerable
---@param predicate fun(value: any, index: any): boolean
function Enumerable:where(predicate)
</syntaxhighlight>
=== zip ===
<syntaxhighlight lang="lua">
--Projects each element of a sequence to an Enumerable and flattens the resulting sequences into one sequence.
---@param self Enumerable
---@param other any
function Enumerable:zip(other)
</syntaxhighlight>
=== zipBy ===
<syntaxhighlight lang="lua">
--Projects each element of a sequence to an Enumerable and flattens the resulting sequences into one sequence.
---@param self Enumerable
---@param other any
---@param resultSelector? fun(left: any, right: any): any
function Enumerable:zipBy(other, resultSelector)
</syntaxhighlight>
=== toDictionary ===
<syntaxhighlight lang="lua">
---@param self Enumerable
---@param keySelector fun(item: any, index: any): any
---@param valueSelector fun(item: any, index: any): any
---@return table
function Enumerable:toDictionary(keySelector, valueSelector)
</syntaxhighlight>
=== toTable ===
<syntaxhighlight lang="lua">
---@param self Enumerable
---@return table
function Enumerable:toTable()
</syntaxhighlight>
=== toHashSet ===
<syntaxhighlight lang="lua">
---@param self Enumerable
---@return table
function Enumerable:toHashSet()
</syntaxhighlight>
</onlyinclude>

Latest revision as of 20:02, 26 July 2024

Contains all shorthand functions that convert one Enumerable object into another. Most of these functions can be chained together to result in a state machine that captures all of the applied functions. The state machine is only executed once a pairs or ipairs operator is applied to the state machine, or by manually progressing the Module:FunList/Enumerator.


Functions

all

-- Determines whether all elements of a sequence satisfy a condition.
---@param self Enumerable
---@param predicate fun(item: any): boolean
---@return boolean
function Enumerable:all(predicate)

any

-- Determines whether any element of a sequence exists or satisfies a condition.
---@param self Enumerable
---@param predicate fun(item: any): boolean
---@return boolean
function Enumerable:any(predicate)

append

-- Adds an item to the end of the enumerable.
---@param self Enumerable
---@param item any
function Enumerable:append(item)

prepend

-- Adds an item to the front of the enumerable.
---@param self Enumerable
---@param item any
function Enumerable:prepend(item)

contains

-- Determines whether a sequence contains a specified element.
---@param self Enumerable
---@param item any
---@return boolean
function Enumerable:contains(item)

count

-- Returns the number of elements in a sequence.
---@param self Enumerable
---@return integer
function Enumerable:count()

first

-- Returns the first element of a sequence.
---@param self Enumerable
---@param predicate? fun(item: any): boolean
---@return any
function Enumerable:first(predicate)

firstOrDefault

-- Returns the first element of a sequence, or a default value if no element is found.
---@param self Enumerable
---@param predicate? fun(item: any): boolean
---@param defaultItem? any
---@return any
function Enumerable:firstOrDefault(predicate, defaultItem)

last

-- Returns the last element of a sequence.
---@param self Enumerable
---@return any
function Enumerable:last()

lastOrDefault

-- Returns the last element of a sequence, or a default value if no element is found.
---@param self Enumerable
---@param defaultItem? any
---@return any
function Enumerable:lastOrDefault(defaultItem)

max

-- Returns the maximum value in a sequence of values.
---@param self Enumerable
---@return number
function Enumerable:max()

min

-- Returns the minimum value in a sequence of values.
---@param self Enumerable
---@return number
function Enumerable:min()

sum

-- Returns the sum value of a sequence of values.
function Enumerable:sum()

concat

-- Adds elements from one sequence to the other.
---@param self Enumerable
---@param other Enumerable
function Enumerable:concat(other)

difference

-- Gets the difference between two sequences
---@param self Enumerable
---@param other Enumerable
function Enumerable:difference(other)

differenceBy

-- Gets the difference between two sequences based on a key
---@param self Enumerable
---@param keySelector? fun(value: any, index: any): any
function Enumerable:differenceBy(other, keySelector)

flatMap

-- Maps items from one sequence to another.
---@param self Enumerable
---@param selector fun(value: any, index: integer): any
function Enumerable:flatMap(selector)

groupBy

--Groups the elements of a sequence.
---@param self Enumerable
---@param keySelector fun(param: any): any
---@param elementSelector? fun(param: any): any
function Enumerable:groupBy(keySelector, elementSelector)

groupByResult

--Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. The elements of each group are projected by using a specified function.
---@param self Enumerable
---@param keySelector fun(param: any): any
---@param elementSelector? fun(param: any): any
---@param resultSelector fun(key: any, grouping: Grouping): any
function Enumerable:groupByResult(keySelector, elementSelector, resultSelector)

intersect

--Produces the set intersection of two sequences.
---@param self Enumerable
---@param other Enumerable
function Enumerable:intersect(other)

intersectBy

--Produces the set intersection of two sequences according to a specified key selector function.
---@param self Enumerable
---@param other Enumerable
---@param keySelector? fun(value: any, index: any): any
function Enumerable:intersectBy(other, keySelector)

map

--Projects each element of a sequence into a new form.
---@param self Enumerable
---@param selector fun(value: any, index: any): any
function Enumerable:map(selector)

sort

--Sorts a sequence.
---@param self Enumerable
---@return SortableIterator
function Enumerable:sort()

sortDescending

--Sorts a sequence in descending order.
---@param self Enumerable
---@return SortableIterator
function Enumerable:sortDescending()

sortBy

--Sorts a sequence based on a specified key selector function.
---@param self Enumerable
---@return SortableIterator
function Enumerable:sortBy(keySelector)

sortByDescending

--Sorts a sequence based on a specified key selector function in descending order.
---@param self Enumerable
---@return SortableIterator
function Enumerable:sortByDescending(keySelector)

thenSortBy

--Sorts a sorted sequence further based on a specified key selector function.
---@param self SortableIterator
---@return SortableIterator
function Enumerable:thenSortBy(keySelector)

thenSortByDescending

--Sorts a sorted sequence further based on a specified key selector function in descending order.
---@param self SortableIterator
---@return SortableIterator
function Enumerable:thenSortByDescending(keySelector)

union

--Produces the set union of two sequences according to a specified key selector function.
---@param self Enumerable
---@param other any
function Enumerable:union(other)

unionBy

--Produces the set union of two sequences according to a specified key selector function.
---@param self Enumerable
---@param other any
---@param keySelector? fun(value: any, index: any): any
function Enumerable:unionBy(other, keySelector)

unique

--Returns unique (distinct) elements from a sequence according to a specified key selector function. 
---@param self Enumerable
function Enumerable:unique()

uniqueBy

--Returns unique (distinct) elements from a sequence according to a specified key selector function. 
---@param self Enumerable
---@param keySelector? fun(value: any, index: any): any
function Enumerable:uniqueBy(keySelector)

where

--Filters a sequence of values based on a predicate.
---@param self Enumerable
---@param predicate fun(value: any, index: any): boolean
function Enumerable:where(predicate)

zip

--Projects each element of a sequence to an Enumerable and flattens the resulting sequences into one sequence.
---@param self Enumerable
---@param other any
function Enumerable:zip(other)

zipBy

--Projects each element of a sequence to an Enumerable and flattens the resulting sequences into one sequence.
---@param self Enumerable
---@param other any
---@param resultSelector? fun(left: any, right: any): any
function Enumerable:zipBy(other, resultSelector)

toDictionary

---@param self Enumerable
---@param keySelector fun(item: any, index: any): any
---@param valueSelector fun(item: any, index: any): any
---@return table
function Enumerable:toDictionary(keySelector, valueSelector)

toTable

---@param self Enumerable
---@return table
function Enumerable:toTable()

toHashSet

---@param self Enumerable
---@return table
function Enumerable:toHashSet()