Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

What Is the Airspeed Velocity of an Unladen Iterator?

The Bridgekeeper squints at the approaching figure.

“What… is your Symbol:iterator?”

“I have one,” says the iterator. “I return myself.”

“What… is your airspeed velocity?”

“I’m lazy — I don’t compute anything until you call next.”

“Then what good are you?”

“I save memory. I can represent infinite sequences. I produce values on demand. And I make for-of work.”

The Bridgekeeper considers this. “How do I know you’re done?”

“I return { done: true }.”

“And if you’re never done?”

“Then I’m a generator. I yield values forever, or until someone breaks. The question isn’t whether I’m done — the question is whether you’re done asking.”

The Bridgekeeper, having no follow-up question about lazy evaluation, waves the iterator through.