v154 · iterator includes
Sequences with no end
A generator that never returns is a perfectly ordinary thing to write — the naturals, a repeating schedule, a stream of samples. Asking whether one contains a value used to be a question you could not ask, because the only method available started by trying to build the whole thing.
Search an endless sequence
The eager column is not run. [...naturals()] allocates until the tab dies; there is no timeout that saves it, because the loop never yields. The demo reports what it would do rather than doing it, which is the only honest way to show this.
| approach | result | values pulled | time |
|---|---|---|---|
| Not run yet. | |||
A target that never appears is the honest limitation: includes on an endless sequence that does not contain the value does not return either. The method makes the answerable questions answerable; it does not decide undecidable ones. The guard below is what production code needs — take() before includes().
The guard you actually write
// Unbounded: correct when the value is there, hangs when it is not.
naturals().includes(target);
// Bounded: an answer either way, at a cost you chose.
naturals().take(1_000_000).includes(target);