Course contentsShow
← JavaScript
Lesson 2015 of 2,72342. Iteration Protocols Deep DiveFree lesson

Iterator Helpers Proposal

Upcoming iterator helpers like .map(), .filter(), and .take() work on any iterator.

Iterator Helpers Proposal

What you'll learn: How upcoming iterator helpers will let you transform and filter any iterator with familiar array-like methods.

The Problem They Solve

Right now, if you create a custom iterator (say, a generator that yields numbers), you can't call .map() or .filter() on it directly—those methods only exist on arrays. You'd need to convert your iterator to an array first with Array.from() or the spread operator, which defeats the lazy, memory-efficient nature of iterators.

What Iterator Helpers Provide

The Iterator Helpers proposal adds methods directly to the iterator protocol itself. This means any iterator—whether from a generator, a custom iterable object, or even a built-in like Map.keys()—will gain methods like:

  • .map(fn) – Transform each value lazily
  • .filter(fn) – Skip values that don't match
  • .take(n) – Take only the first n values
  • .drop(n) – Skip the first n values
  • .flatMap(fn) – Map and flatten in one step

These helpers return new iterators, not arrays, so they compose efficiently without creating intermediate data structures.

The Big Win

// Instead of converting to array:
const nums = (function* () { yield 1; yield 2; yield 3; }());
const result = Array.from(nums).filter(x => x > 1).map(x => x * 2);

// Iterator helpers let you stay lazy:
// nums.filter(x => x > 1).map(x => x * 2) // (when proposal lands)

The iteration only happens when you actually consume the final iterator—perfect for large or infinite sequences.

Key Takeaway: Iterator helpers bring array-like methods (.map(), .filter(), .take()) to all iterators, letting you transform data lazily without converting to arrays first.