You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Turns an iterator into an array of the remaining values.
51
51
Remember that each invocation of `next` of an iterator consumes a value. `Iterator.toArray` will consume all remaining values of the iterator and return them in an array to you.
52
52
53
-
See [iterator protocols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) on MDN.
53
+
See [Iterator.prototype.toArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/toArray) on MDN.
54
54
55
55
## Examples
56
56
```rescript
@@ -64,13 +64,14 @@ let mapKeysAsArray = map->Map.keys->Iterator.toArray
64
64
Console.log(mapKeysAsArray) // Logs ["someKey", "someKey2"] to the console.
65
65
```
66
66
*/
67
-
externaltoArray: t<'a> =>array<'a> ="Array.from"
67
+
@send
68
+
externaltoArray: t<'a> =>array<'a> ="toArray"
68
69
69
70
/**
70
71
`toArray(iterator)` turns `iterator` into an array of its remaining values, applying the provided mapper function on each item.
71
72
Remember that each invocation of `next` of an iterator consumes a value. `Iterator.toArrayWithMapper` will consume all remaining values of the iterator and return them in an array to you.
72
73
73
-
See [iterator protocols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) on MDN.
74
+
See [Iterator.prototype.toArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/toArray) on MDN.
74
75
75
76
## Examples
76
77
```rescript
@@ -95,25 +96,18 @@ See [iterator protocols](https://developer.mozilla.org/en-US/docs/Web/JavaScript
95
96
96
97
## Examples
97
98
```rescript
98
-
let iterator: Iterator.t<string> = %raw(`
99
-
(() => {
100
-
var array1 = ['a', 'b', 'c'];
101
-
var iterator1 = array1[Symbol.iterator]();
102
-
return iterator1
103
-
})()
104
-
`)
99
+
let iterator: Iterator.t<string> = ["a", "b", "c"]->Array.values
let areAllEven = fibonacci->Iterator.every(n => n % 2 == 0)
147
+
Console.log(areAllEven) // false
148
+
```
149
+
*/
150
+
@send
151
+
externalevery: (t<'a>, 'a=>bool) =>bool="every"
152
+
153
+
/**
154
+
`filter(iterator, fn)` returns a new iterator helper object that contains the elements of the original iterator that pass the test implemented by the provided function.
155
+
156
+
See [Iterator.prototype.filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/filter) on MDN.
`flatMap(iterator, fn)` returns a new iterator helper object that contains the elements of the original iterator that pass the test implemented by the provided function.
188
+
189
+
See [Iterator.prototype.flatMap](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/flatMap) on MDN.
190
+
191
+
## Examples
192
+
```rescript
193
+
let map1 = Map.fromArray([("a", 1), ("b", 2), ("c", 3)])
194
+
let map2 = Map.fromArray([("d", 4), ("e", 5), ("f", 6)])
`map(iterator, fn)` returns a new iterator helper object that yields elements of the iterator, each transformed by a mapping function.
208
+
209
+
See [Iterator.prototype.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/map) on MDN.
210
+
211
+
## Examples
212
+
```rescript
213
+
let map = Map.fromArray([("a", 1), ("b", 2), ("c", 3)])
214
+
let letters = map->Map.keys->Iterator.map(v => v->String.toUpperCase)->Array.fromIterator
215
+
Console.log(letters) // ["A", "B", "C"]
216
+
```
217
+
*/
218
+
@send
219
+
externalmap: (t<'a>, 'a=>'b) =>t<'b> ="map"
220
+
221
+
/**
222
+
`reduce(iterator, fn, initialValue)` applies a function against an accumulator and each element in the iterator (from left to right) to reduce it to a single value.
223
+
224
+
See [Iterator.prototype.reduce](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/reduce) on MDN.
225
+
226
+
## Examples
227
+
```rescript
228
+
let numbers: Iterator.t<int> = [ 1, 2, 3 ]->Array.entries
229
+
230
+
let sum = numbers->Iterator.reduce((acc, n) => acc + n, ~initialValue=0)
0 commit comments