Lazily Enumerating Combinations of Two Inputs

An iterator can produce ordered pairs on demand without materializing the full Cartesian product.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Trace a stop after two results
  2. Check source reiterability

Trace a stop after two results

With A and B on the left and 1, 2, 3 on the right, a left-first traversal can emit A1 and A2 and pause. The entire result contains six pairs, following the product rule.

Check source reiterability

If the inner input is a one-pass stream, restarting it after A may not yield three values for B. Retain a bounded copy or use a different traversal when needed. Iterator exhaustion explains the constraint.[1]

References

  1. Python Software Foundation, Functional Programming HOWTO ↩