@kingjs/linq.select-many

Generate a sequence by concatenating sequences projected from elements of a sequence.

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
03Jun 12, 2021Jul 20, 2018Minified + gzip package size for @kingjs/linq.select-many in KB

Readme

@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

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.