.map(fn) Transform each value
Lazily applies fn to each yielded value, returning a new iterator.
.filter(fn) Keep matching values
Yields only the values for which fn returns truthy.
.take(n) First n values
Yields at most n values, then closes the iterator. Works safely on infinite iterators.
.drop(n) Skip first n values
Skips the first n values, then yields the rest.
.flatMap(fn) Map + flatten
Maps each value through fn (which must return an iterable or iterator) and flattens one level.
.reduce(fn, init) Accumulate into a single value
Consumes the iterator, reducing all values into a single result. Eager operation.
.toArray() Collect into an array
Consumes the iterator and returns all yielded values as an Array.
.forEach(fn) Execute side effects
Consumes the iterator, calling fn for each value. Returns undefined.
.some(fn) Any match?
Returns true as soon as fn returns truthy for a value. Short-circuits.
.every(fn) All match?
Returns true only if fn returns truthy for every value. Short-circuits on first false.
.find(fn) First match
Returns the first value for which fn returns truthy, or undefined. Short-circuits.
Lazy Evaluation Demo
Iterator helpers are lazy -- intermediate steps like .map() and .filter() only execute when a value is actually consumed. This demo proves it by logging which elements get processed.
Eager: Array methods
Click "Run Comparison" to see the difference.
Lazy: Iterator Helpers
Click "Run Comparison" to see the difference.
Pipeline Builder
Chain multiple iterator helpers visually. Add steps, configure arguments, and run the pipeline. Each step executes lazily.