This package has been deprecated

Author message:

none

@kingjs/enumerable.from-each

1.0.2 • Public • Published

@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

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

Readme

Keywords

none

Package Sidebar

Install

npm i @kingjs/enumerable.from-each

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

4.83 kB

Total Files

4

Last publish

Collaborators

  • kingces95