1.0.7 • Published 6 years ago
@kingjs/linq.select-many v1.0.7
@kingjs/linq.select-many
Generate a sequence by concatenating sequences projected from elements of a sequence.
Usage
List all pets and their owners given a list of people and their pets like this:
var selectMany = require('@kingjs/linq.select-many');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');
var peopleAndPets = sequence(
{ name: 'Alice', pets: sequence('Tiger', 'Butch') },
{ name: 'Bob', pets: sequence('Spike', 'Fluffy') }
);
var petOwners = selectMany.call(
peopleAndPets,
function(x, i) { return x.pets; },
function(x, p) { return x.name + ' owns ' + p; }
)
toArray.call(petOwners);
result:
[
'Alice owns Tiger',
'Alice owns Butch',
'Bob owns Spike',
'Bob owns Fluffy'
]
API
function selectMany(
this: Enumerable,
collectionSelector?: (x, i) => Enumerable,
resultSelector?: (x, y) => any
): Enumerable
Interfaces
Enumerable
: See @kingjs/enumerable.define.
Parameters
this
: A sequence each element of which can be transformed into another sequence.collectionSelector
: Return a sequence given an element ofthis
.x
: The element to transform into a sequence.i
: The index of the element being transformed into a sequence.
resultSelector
: Transform an element of the sequence derived fromx
.x
: The element transformed into a sequence of whichy
is a member.y
: The element of sequence derived fromx
to transform.
Return Value
A flattened transformed version of the original sequence.
Install
With npm installed, run
$ npm install @kingjs/link.select-many
Acknowledgments
License
MIT