Skip to main content

CombinationsGenerator class

Generates all possible combinations from a matrix of parameters.

Signature

export declare class CombinationsGenerator

Remarks

This class computes the Cartesian product of multiple parameter arrays, producing all possible combinations of parameter values using a memory-efficient generator pattern. It uses a recursive algorithm to systematically explore all combinations one at a time.

The generation process:

  1. Takes arrays of parameter names (keys) and their corresponding value arrays.
  2. Recursively iterates through each parameter, selecting one value at a time.
  3. Yields complete combinations one at a time without storing them all in memory.
  4. Backtracks to explore other value combinations.

Example usage:

const generator = new CombinationsGenerator({
matrixKeys: ['arch', 'optimize'],
matrixValues: [['x64', 'arm'], ['speed', 'size']],
log
});
for (const combo of generator.generate()) {
// Process one combination at a time without storing all in memory
// Results:
// { arch: 'x64', optimize: 'speed' }
// { arch: 'x64', optimize: 'size' }
// { arch: 'arm', optimize: 'speed' }
// { arch: 'arm', optimize: 'size' }
await processConfiguration(combo);
}

Constructors

Constructor

Modifiers

Description

(constructor)({ matrixKeys, matrixValues, maxCombinations, log, }, input)

Constructs a combinations generator instance.

Properties

Property

Modifiers

Type

Description

_log

protected

readonly

Logger

The logger instance for output and diagnostics.

_matrixKeys

protected

readonly

string[]

The array of parameter names.

_matrixValues

protected

readonly

string[][]

The array of value arrays for each parameter.

_maxCombinations

protected

readonly

number

The maximum number of combinations allowed.

Methods

Method

Modifiers

Description

_generateRecursively(index, combination)

protected

Recursively generates combinations as a generator, yielding one at a time.

generate()

Generates combinations one at a time using a generator pattern.


Generated via tsdoc2docusaurus 1.3.2 by API Extractor/Documenter 7.57.2.