Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions lib/node_modules/@stdlib/math/iter/ops/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,52 @@ The namespace contains the following functions for creating iterator protocol-co

## Examples

<!-- TODO: better examples -->

<!-- eslint no-undef: "error" -->

```javascript
var objectKeys = require( '@stdlib/utils/keys' );
var array2iterator = require( '@stdlib/array/to-iterator' );
var ns = require( '@stdlib/math/iter/ops' );

console.log( objectKeys( ns ) );
// 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
```

</section>
Expand Down
43 changes: 41 additions & 2 deletions lib/node_modules/@stdlib/math/iter/ops/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,46 @@

'use strict';

var objectKeys = require( '@stdlib/utils/keys' );
var array2iterator = require( '@stdlib/array/to-iterator' );
var ns = require( './../lib' );

console.log( objectKeys( ns ) );
// 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
Loading