v154 · iterator includes

Searching a log

A pipeline over records — decode, filter, project, ask. Each stage is lazy, so the question at the end decides how much work the whole chain does. And then the sharp edge: ask twice and the second answer is wrong, because the iterator is gone.

Ask the pipeline a question

Work done by the pipeline
stagecalls
Not run yet.
Pick a code and search.

Why the second answer is different

The same iterator, two questions
questionanswercorrect?
Not run yet.

An iterator is a position in a sequence, not the sequence. includes consumes up to the match and leaves the cursor there, so a second question starts from wherever the first one stopped. If you need to ask twice, build the iterator twice — or materialise it deliberately, once, and pay for it knowingly.

code path

const hadTimeout = records()          // a generator over raw lines
  .map(parse)                         // one object at a time
  .filter((r) => r.level === "error")  // still lazy
  .map((r) => r.code)                 // still lazy
  .includes("E_TIMEOUT");             // pulls until it finds one

see also