@kingjs/linq.select-many

1.0.7 • Public • Published

@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

Parameters

  • this: A sequence each element of which can be transformed into another sequence.
  • collectionSelector: Return a sequence given an element of this.
    • 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 from x.
    • x: The element transformed into a sequence of which y is a member.
    • y: The element of sequence derived from x to transform.

Return Value

A flattened transformed version of the original sequence.

Install

With npm installed, run

$ npm install @kingjs/link.select-many

Acknowledgments

Like Enumerable.SelectMany

License

MIT

Analytics

Readme

Keywords

none

Package Sidebar

Install

npm i @kingjs/linq.select-many

Weekly Downloads

0

Version

1.0.7

License

MIT

Unpacked Size

4.81 kB

Total Files

4

Last publish

Collaborators

  • kingces95