API/Enumerable-Group

Enumerable.prototype:GroupBy(key_selector, element_selector, result_selector, compare_selector)

Groups the elements in the sequence by a given key selector function.

Parameters

key_selector
a function that gets a key from an element
element_selector
optional: a function to project each element in the sequence to an element in the resultant grouping
result_selector
optional: a function to create a result value from each group
compare_selector
optional: an equality comparer


Enumerable.prototype:GroupJoin(inner, outer_key_selector, inner_key_selector, result_selector, compare_selector)

Correlate the elements of two sequences based on matching keys and groups the results

Parameters

inner
the inner sequence to join on
outer_key_selector
a function to get the join key from the first sequence
inner_key_selector
a function to get the join key from the second sequence
result_selector
a function to create a result element from the two matching elements
compare_selector
an equality comparer for the join keys

Usage

Enumerable.From({ {v=1, n="Magnus"}, {v=2, n="Terry"}, {v=3, n="Charlotte"} }):GroupJoin({ { n="Barley", o=2 }, { n="Boots", o=2 }, { n="Whiskers", o=3 }, { n="Daisy", o=1 } }, function(a) return a.v end, function(b) return b.o end, function(a, coll) return a.n .. "-" .. coll:Select(function(b) return b.n end):StringJoin(":") end):ToString() == '["Magnus-Daisy", "Terry-Barley:Boots", "Charlotte-Whiskers"]'
Enumerable.From({ {v=1, n="Magnus"}, {v=2, n="Terry"}, {v=3, n="Charlotte"} }):GroupJoin({ { n="Barley", o=2 }, { n="Boots", o=2 }, { n="Whiskers", o=3 }, { n="Daisy", o=1 } }, "a => a.v", "b => b.o", function(a, coll) return a.n .. "-" .. coll:Select("b => b.n"):StringJoin(":") end):ToString() == '["Magnus-Daisy", "Terry-Barley:Boots", "Charlotte-Whiskers"]'


Enumerable.prototype:Join(inner, outer_key_selector, inner_key_selector, result_selector, compare_selector)

Correlate the elements of two sequences based on matching keys

Parameters

inner
the inner sequence to join on
outer_key_selector
a function to get the join key from the first sequence
inner_key_selector
a function to get the join key from the second sequence
result_selector
a function to create a result element from the two matching elements
compare_selector
an equality comparer for the join keys

Usage

Enumerable.From({ {v=1, n="a"}, {v=2, n="b"} }):Join({ {v=1, x="c"}, {v=2, x="d"} }, function(a) return a.v end, function(b) return b.v end, function(a, b) return a.n .. b.x end):ToString() == '["ac", "bd"]'
Enumerable.From({ {v=1, n="a"}, {v=2, n="b"} }):Join({ {v=1, x="c"}, {v=2, x="d"} }, "a => a.v", "b => b.v", "a, b => a.n .. b.x"):ToString() == '["ac", "bd"]'


Enumerable.prototype:ToLookup(key_selector, element_selector, compare_selector)

Creates a Lookup from this sequence.

Parameters

key_selector
A function to extract a key from each element
element_selector
A transform function to produce a result element value from each element
compare_selector
An equality comparer to compare values

Return value

A Lookup enumerable


Grouping.New(key, elements)

Contruct and return a grouping based on the key and sequence provided

Parameters

key
the key representative of the grouping
elements
the elements contained within the grouping

Return value

a Grouping


Grouping.prototype:GetEnumerator()

Return the enumerator associated with the elements of this grouping

Return value

an Enumerator


Grouping.prototype:Key()

Return the key associated with this grouping

Return value

a key


Grouping.prototype:ToString()

Return the string representation of this grouping

Return value

a string


Lookup.New(dict, keys, compare_selector)

Construct a new Lookup.
This should only be called internally by :ToLookup()

Parameters

dict
a lua table representing a multi-value dict of comparison key to multiple values
keys
a lua table representing a key lookup of comparison key to real key
compare_selector
a function to convert real keys to comparison keys

Return value

a Lookup


Lookup.prototype:Contains(key)

Return whether the key exists in the lookup and has at least one associated value.

Parameters

key
the key to check on

Return value

a boolean


Lookup.prototype:Count()

Return the number of lookup keys

Return value

an integer


Lookup.prototype:Get(key)

Return an enumerable representing the values matched by the key provided.
If the key does not exist in the lookup, an empty Enumerable will be returned.

Parameters

key
the key to check on

Return value

an Enumerable


Lookup.prototype:ToGroupings()

Return an enumerable of Grouping that contains the values of this Lookup

Return value

an Enumerable



Comments

Posts Quoted:
Reply
Clear All Quotes