product-iterable

Make a Cartesian product of iterables, or create a Cartesian power of an iterable

Usage no npm install needed!

<script type="module">
  import productIterable from 'https://cdn.skypack.dev/product-iterable';
</script>

README

product-iterable

Requirements

  • Node >= 6.0.0

Features

  • Make a Cartesian product of iterables

  • Create a Cartesian power of an iterable

Usage

Import

var ProductIterable = require('product-iterable');

Constructor

Cartesian product of iterables

Form

var product = new ProductIterable(...iterables);

Where:

  • ...iterables are finite iterable objects

  • product is an iterable of tuples

Example

var product = new ProductIterable('abc', [0, 1, 2, 3]);
console.log(new Set(product));

You would seen a set of (character, number) pairs

Function: ::pow a.k.a ::times

Cartesian power of an iterable

Form

var power = ProductIterable.pow(iterable, exponent);

Where:

  • iterable is a finite iterable object, let's suppose its length equal to L

  • exponent is an unsigned integer, let's call it E

  • power is an iterable object which iterates LE number of arrays of iterable's elements

Example

var power = ProductIterable.pow('abcd', 3);
console.log(new Set(power));

Just like new ProductIterable('abcd', 'abcd', 'abcd'), you would seen a set of 43 arrays