@@ -63,15 +63,52 @@ The namespace contains the following functions for creating iterator protocol-co
63
63
64
64
## Examples
65
65
66
- <!-- TODO: better examples -->
67
-
68
66
<!-- eslint no-undef: "error" -->
69
67
70
68
``` javascript
71
- var objectKeys = require ( ' @stdlib/utils/keys ' );
69
+ var array2iterator = require ( ' @stdlib/array/to-iterator ' );
72
70
var ns = require ( ' @stdlib/math/iter/ops' );
73
71
74
- console .log ( objectKeys ( ns ) );
72
+ // Demonstrate operations with two iterators:
73
+ var arr1 = [ 2.0 , 3.0 ];
74
+ var arr2 = [ 1.0 , 4.0 ];
75
+ var itAdd = ns .iterAdd ( array2iterator ( arr1 ), array2iterator ( arr2 ) );
76
+ var itDiv = ns .iterDivide ( array2iterator ( arr1 ), array2iterator ( arr2 ) );
77
+ var itMul = ns .iterMultiply ( array2iterator ( arr1 ), array2iterator ( arr2 ) );
78
+ var itSub = ns .iterSubtract ( array2iterator ( arr1 ), array2iterator ( arr2 ) );
79
+
80
+ // Addition: 2+1=3, 3+4=7
81
+ console .log ( itAdd .next ().value );
82
+ // => 3.0
83
+ console .log ( itAdd .next ().value );
84
+ // => 7.0
85
+
86
+ // Division: 2/1=2, 3/4=0.75
87
+ console .log ( itDiv .next ().value );
88
+ // => 2.0
89
+ console .log ( itDiv .next ().value );
90
+ // => 0.75
91
+
92
+ // Multiplication: 2*1=2, 3*4=12
93
+ console .log ( itMul .next ().value );
94
+ // => 2.0
95
+ console .log ( itMul .next ().value );
96
+ // => 12.0
97
+
98
+ // Subtraction: 2-1=1, 3-4=-1
99
+ console .log ( itSub .next ().value );
100
+ // => 1.0
101
+ console .log ( itSub .next ().value );
102
+ // => -1.0
103
+
104
+ // Demonstrate operation with iterator and constant
105
+ var it3 = array2iterator ( [ 1.0 , 2.0 ] );
106
+ var itWithConstant = ns .iterAdd ( it3, 3.0 );
107
+
108
+ console .log ( itWithConstant .next ().value );
109
+ // => 4.0
110
+ console .log ( itWithConstant .next ().value );
111
+ // => 5.0
75
112
```
76
113
77
114
</section >
0 commit comments