You’ll learn how JavaScript hands out values one at a time: iterators, generators, lazy pipelines and async feeds. You’ll help Priya port her weather station’s feed to JavaScript.
The station sends one temperature at a time, and a dropped reading arrives as None. Here’s a first taste. In Priya’s Python, the valid() generator prints each reading and skips
dropped ones, and islice() takes the first two:
from itertools import islice
readings = [12.5, 13.1, None, 14.0, 13.6, 15.2]
def valid(values):
for value in values:
print("read", value)
if value is not None:
yield value
print(list(islice(valid(readings), 2)))
Python reads two readings, then prints them:
read 12.5
read 13.1
[12.5, 13.1]
With the array methods you know, the JavaScript port uses .slice() for islice(), and .filter() for
the generator:
const readings = [12.5, 13.1, null, 14.0, 13.6, 15.2];
const first = readings
.filter((value) => {
console.log("read", value);
return value !== null;
})
.slice(0, 2);
console.log(first);
It reads all six readings, then logs the same two:
read 12.5
read 13.1
read null
read 14
read 13.6
read 15.2
[ 12.5, 13.1 ]
Keeping the port lazy is the job ahead, because a live feed never ends.
Priya’s Python service steps through the readings one at a time, with an iterator class. A generator filters out
dropped reads, islice() takes the first few, and async for reads the live feed. Now the feed moves to
JavaScript, one piece at a time.
By the end of this course, you’ll be able to:
- Write the full iteration protocol by hand, so
for...ofcan walk an iterator you wrote yourself - Use
function*generators to write iterators, and send values into them - Chain lazy iterator helpers, such as
.drop()and.take(), on an iterator - Find JavaScript equivalents for the
itertoolsfunctions you use - Consume async feeds with
for await...of
In Python, you only need to know how to write custom iterator classes and generators, and how to use
itertools and async for. In JavaScript, you only need to know classes, arrow functions and array methods,
and async functions with await.
You’ll need Node 26 or later installed, and no packages. The examples use Node 26 and Python 3.15.
The course mixes short videos with text lessons and exercises. Every video has a summary below it. A quiz and a summary close the course.
Next up: Writing an Iterator by Hand, where you port Priya’s Feed class, iterator and all.