Home Manual Reference Source

Function

Static Public Summary
public

* diagonal(A: Iterable, B: Iterable): IterableIterator

Computes the product of two iterables in a way that allows for one or both of them to be infinite (in contrast with product).

public

product(iterables: Iterable<Iterable>, repeat: number): IterableIterator

Computes the product of the iterables given as first parameter.

Static Private Summary
private

* _product(pools: Array<Iterable>, i: number, n: number): IterableIterator

Algorithm used by product to compute the product of one or more iterables from pools of symbols.

Static Public

public * diagonal(A: Iterable, B: Iterable): IterableIterator source

Computes the product of two iterables in a way that allows for one or both of them to be infinite (in contrast with product). Although the output iterator may be infinite, it is guaranteed that each value of the product is located at some finite position in the output iterator.

If one of the two inputs has finite size N, it is guaranteed that memory usage never exceeds O(N) values. If both inputs have infinite size, then memory usage grows proportionally to the square root of the number of output pairs.

Params:

NameTypeAttributeDescription
A Iterable

The first iterable.

B Iterable

The second iterable.

Return:

IterableIterator

Example:

// returns [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 0 ] , [ 1 , 1 ] ]
list( diagonal( range( 2 ) , range( 2 ) ) ) ;

public product(iterables: Iterable<Iterable>, repeat: number): IterableIterator source

Computes the product of the iterables given as first parameter. The second parameter is an integer that tells how many times the list of iterables given as input should be concatenated to itself before computing the product. This second parameter is optional and its default value is 1.

Params:

NameTypeAttributeDescription
iterables Iterable<Iterable>

The input iterables.

repeat number

The number of times to cycle through the input iterables.

Return:

IterableIterator

Example:

// Ax Ay Bx By Cx Cy Dx Dy
product(['ABCD', 'xy']) ;
// 000 001 010 011 100 101 110 111
product([range(2)], 3) ;

Static Private

private * _product(pools: Array<Iterable>, i: number, n: number): IterableIterator source

Algorithm used by product to compute the product of one or more iterables from pools of symbols.

Params:

NameTypeAttributeDescription
pools Array<Iterable>

The pools of symbols in reverse order.

i number

Index of the pool to draw the next symbol from

n number

Number of pools in total.

Return:

IterableIterator

Example:

// Ax Ay Bx By Cx Cy Dx Dy
_product(['xy', 'ABCD'], 0 , 2) ;
// 000 001 010 011 100 101 110 111
_product([[0,1],[0,1],[0,1]], 0 , 3) ;