@kingjs/enumerable.from-each

Generates a sequence of arrays or descriptors composed of a single element each from a set of arrays.

Stats

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

Readme

@kingjs/enumerable.from-each

Generates a sequence of arrays or descriptors composed of a single element each from a set of arrays.

Usage

Generate the cross product of shirts sizes (small, medium, and large) and colors (red and green) like this:

var fromEach = require('@kingjs/enumerable.from-each');
var toArray = require('@kingjs/linq.to-array');

var shirts = fromEach({
  size: [ 'S', 'M', 'L' ],
  color: [ 'Red', 'Green' ]
});

toArray.call(shirts);

results:

[
  { size: 'S', color: 'Red' },
  { size: 'M', color: 'Red' },
  { size: 'L', color: 'Red' },
  { size: 'S', color: 'Green' },
  { size: 'M', color: 'Green' },
  { size: 'L', color: 'Green' }
];

Generate the same cross product except use an array instead of a descriptor to express the set of arrays like this:

var fromEach = require('@kingjs/enumerable.from-each');
var toArray = require('@kingjs/linq.to-array');

var shirts = fromEach([
  [ 'S', 'M', 'L' ], 
  [ 'Red', 'Green' ]
]);

toArray.call(shirts);

result:

[
  [ 'S', 'Red' ],
  [ 'M', 'Red' ],
  [ 'L', 'Red' ],
  [ 'S', 'Green' ],
  [ 'M', 'Green' ],
  [ 'L', 'Green' ]
];

API

function fromEach(
  data: any[][] | { [index: string]: any[] }
): Enumerator

Interfaces

  • Enumerable: See @kingjs/enumerable.define.

    Parameters

  • data: An array of arrays, or a descriptor whose every property is an array.

    Return Value

    A sequence of arrays or descriptors where each index or property is replaced with an element of its corresponding array.

    Install

    With npm installed, run
    $ npm install @kingjs/enumerable.from-each
    

    Acknowledgments

    Like nUnit ValuesAttribute and TheoryAttribute which use an odometer to generate combinations of test values from a set of arrays.

    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.