Skip to content

Latest commit

 

History

History
154 lines (91 loc) · 4.08 KB

File metadata and controls

154 lines (91 loc) · 4.08 KB

iterCartesianSquare

Create an iterator which iteratively computes the Cartesian square.

Usage

var iterCartesianSquare = require( '@stdlib/iter/cartesian-square' );

iterCartesianSquare( x )

Returns an iterator of the Cartesian square.

var x = [ 1, 2 ];

var iter = iterCartesianSquare( x );
// returns <Object>

var v = iter.next().value;
// returns [ 1, 1 ]

v = iter.next().value;
// returns [ 1, 2 ]

v = iter.next().value;
// returns [ 2, 1 ]

// ...

The returned iterator protocol-compliant object has the following properties:

  • next: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a value property and a done property having a boolean value indicating whether the iterator is finished.
  • return: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object.

Notes

  • If an environment supports Symbol.iterator and a provided iterator is iterable, the returned iterator is iterable.

Examples

var linspace = require( '@stdlib/array/linspace' );
var iterCartesianSquare = require( '@stdlib/iter/cartesian-square' );

var x = linspace( 0, 5, 6 );

// Create an iterator which iteratively computes the Cartesian square:
var it = iterCartesianSquare( x );

// Perform manual iteration...
var v;
while ( true ) {
    v = it.next();
    if ( v.done ) {
        break;
    }
    console.log( v.value );
}

See Also