selectMany()
selectMany(callable $collectionSelector = null, callable|null $resultSelectorValue = null, callable|null $resultSelectorKey = null) : \YaLinqo\Enumerable
Projects each element of a sequence to a sequence and flattens the resulting sequences into one sequence.
Syntax: selectMany ()
The selectMany method enumerates the input sequence, where each element is a sequence, and then enumerates and yields the elements of each such sequence. That is, for each element of source, selectorValue and selectorKey are invoked and a sequence of key-value pairs is returned. selectMany then flattens this two-dimensional collection of collections into a one-dimensional sequence and returns it. For example, if a query uses selectMany to obtain the orders for each customer in a database, the result is a sequence of orders. If instead the query uses \select to obtain the orders, the collection of collections of orders is not combined and the result is a sequence of sequences of orders.
Syntax: selectMany (collectionSelector {(v, k) ==> enum})
The selectMany method enumerates the input sequence, uses transform functions to map each element to a sequence, and then enumerates and yields the elements of each such sequence.
Syntax: selectMany (collectionSelector {(v, k) ==> enum} [, resultSelectorValue {(v, k1, k2) ==> value} [, resultSelectorKey {(v, k1, k2) ==> key}]])
Projects each element of a sequence to a sequence, flattens the resulting sequences into one sequence, and invokes a result selector functions on each element therein.
The selectMany method is useful when you have to keep the elements of source in scope for query logic that occurs after the call to selectMany. If there is a bidirectional relationship between objects in the source sequence and objects returned from collectionSelector, that is, if a sequence returned from collectionSelector provides a property to retrieve the object that produced it, you do not need this overload of selectMany. Instead, you can use simpler selectMany overload and navigate back to the source object through the returned sequence.
Parameters
callable |
$collectionSelector |
{(v, k) ==> enum} A transform function to apply to each element. |
callable|null |
$resultSelectorValue |
{(v, k1, k2) ==> value} A transform function to apply to each value of the intermediate sequence. Default: {(v, k1, k2) ==> v}. |
callable|null |
$resultSelectorKey |
{(v, k1, k2) ==> key} A transform function to apply to each key of the intermediate sequence. Default: increment. |
Returns
\YaLinqo\Enumerable
— A sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.