import { Sync } from "https://unpkg.com/ixfx/dist/iterables.js"
Sync.forEach(count(5), () => console.log(`Hi`)); // Prints `Hi` 5x
Sync.forEach(count(5), i => console.log(i)); // Prints 0 1 2 3 4
Sync.forEach([0,1,2,3,4], i => console.log(i)); // Prints 0 1 2 3 4
Use forEach if you want to use an async iterator
and async fn
.
Alternatives:
Iterates over
iterator
(iterable/array), callingfn
for each value. Iffn
returns false, iterator cancels.Over the default JS
forEach
function, this one allows you to exit the iteration early.