Create an iterator which iteratively computes the Cartesian square.
var iterCartesianSquare = require( '@stdlib/iter/cartesian-square' );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
valueproperty and adoneproperty having abooleanvalue indicating whether the iterator is finished. - return: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object.
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 );
}@stdlib/array/cartesian-square: return then Cartesian square.