Skip to content

Files

Latest commit

43ac1e7 · Oct 30, 2024

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jan 7, 2024
Jan 7, 2024
Jan 7, 2024
Oct 30, 2024
Dec 16, 2020
Jan 7, 2024
Jan 7, 2024
Jan 7, 2024
Jul 24, 2023
Oct 30, 2024
Oct 14, 2021

Operators

Math operator iterators.

Usage

var ns = require( '@stdlib/math/iter/ops' );

ns

Namespace containing math operator iterators.

var iterators = ns;
// returns {...}

The namespace contains the following functions for creating iterator protocol-compliant iterators:

Examples

var array2iterator = require( '@stdlib/array/to-iterator' );
var ns = require( '@stdlib/math/iter/ops' );

// Demonstrate operations with two iterators:
var arr1 = [ 2.0, 3.0 ];
var arr2 = [ 1.0, 4.0 ];
var itAdd = ns.iterAdd( array2iterator( arr1 ), array2iterator( arr2 ) );
var itDiv = ns.iterDivide( array2iterator( arr1 ), array2iterator( arr2 ) );
var itMul = ns.iterMultiply( array2iterator( arr1 ), array2iterator( arr2 ) );
var itSub = ns.iterSubtract( array2iterator( arr1 ), array2iterator( arr2 ) );

// Addition: 2+1=3, 3+4=7
console.log( itAdd.next().value );
// => 3.0
console.log( itAdd.next().value );
// => 7.0

// Division: 2/1=2, 3/4=0.75
console.log( itDiv.next().value );
// => 2.0
console.log( itDiv.next().value );
// => 0.75

// Multiplication: 2*1=2, 3*4=12
console.log( itMul.next().value );
// => 2.0
console.log( itMul.next().value );
// => 12.0

// Subtraction: 2-1=1, 3-4=-1
console.log( itSub.next().value );
// => 1.0
console.log( itSub.next().value );
// => -1.0

// Demonstrate operation with iterator and constant
var it3 = array2iterator( [ 1.0, 2.0 ] );
var itWithConstant = ns.iterAdd( it3, 3.0 );

console.log( itWithConstant.next().value );
// => 4.0
console.log( itWithConstant.next().value );
// => 5.0