Loading video player…

Welcome to the Weather Station Feed

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:

Language: Python
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:

Language: Program Output
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:

Language: JavaScript
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:

Language: Program Output
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...of can 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 itertools functions 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.

Download

Sample Code (.zip)

11.7 KB
Download

Course Slides (.pdf)

461.8 KB

00:00 Welcome to JavaScript Iterators and Generators for Pythonistas! You’ll learn how JavaScript hands out values one at a time: iterators, generators, lazy pipelines and async feeds.

00:12 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.

00:21 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.

00:32 Python reads two, then prints them.

00:35 With the array methods you know, the JavaScript port uses slice for islice(), and filter for the generator. It reads all six readings. Then it logs the same two.

00:49 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.

01:00 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.

01:13 You’ll write the iteration protocol by hand, then write generators. You’ll chain iterator helpers and find your itertools. Then you’ll read a live feed.

01:25 You need to know Python’s iterator classes, generators, itertools and async for. And JavaScript’s classes, arrow functions, array methods and async functions.

01:37 The examples use Node 26 and Python 3.15.

01:42 Short videos mix with text lessons and exercises, and 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.

Become a Member to join the conversation.