jlongster / transducers.js

A small library for generalized transformation of data (inspired by Clojure's transducers)
BSD 2-Clause "Simplified" License
1.73k stars 54 forks source link

seq(iterable, take(5)) seems to yield infinite loop #50

Open rasmusvhansen opened 6 years ago

rasmusvhansen commented 6 years ago

I would expect this code to print 0 2 4 6 8 and then terminate. Instead it prints 0 2 4 6 8 and then uses all cpu indefinitely. Am I using it wrong?

function* nums() {
  let i = 0;
  while (true) {
    yield i++;
  }
}

let res = seq(nums(), compose(map(x => x * 2), take(5)));

for (let x of res) {
  console.log(x);
}

If I instead use res = into([], compose(map(x => x * 2), take(5)), nums()); It terminates as expected.