demo · v146

Pull trace

Visualises every next() call as it travels through a concatenated chain. Source A holds 6 values, source B holds 6, source C holds infinitely many. As you slide the take(n) dial, watch which cells light up — blue is "pulled", green is "delivered to caller", grey is "never touched". Eager spread would pull every finite source dry; lazy stops the instant the consumer is satisfied.

pulled delivered never touched eager finite pull
source A (size 6)
source B (size 6)
source C (∞)
0total pulls
0delivered
0cells untouched
const a = [1, 2, 3, 4, 5, 6];
const b = [-1, 7, 8, 9, 10, 11];
function* c() { let i = 100; while (true) yield i++; }

const result = Iterator.concat(a, b, c())
  .drop(1)
  .filter(x => x > 0)
  .take(N)
  .toArray();
// concat is lazy → c() is only entered if a + b ran dry first
// Eager comparison, shown as an overlay only:
const eager = [...a, ...b, ...c()];
// c() is infinite, so the spread would never finish.

see also