jlongster / transducers.js

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

no @@iterator method on iterators? #37

Open jaawerth opened 9 years ago

jaawerth commented 9 years ago

Hey there!

I noticed that iterators produced by the toIter and iterator methods don't have a Symbol.iterator/@@iterator method on them and thus won't work with for..in, yield*, new Set(), etc. This is mentioned in the comments as part of iterator protocol, so before I submit a PR I was wondering: is that an intentional omission?

It'd be nice to have in ES6, so the resultant iterators can be used with things like

function* flatten(iterable) {
  for (let item of iterable) {
    if (item[Symbol.iterator]) yield* flatten(item);
    yield item;
  }
}
jlongster commented 9 years ago

You're right, it looks like that should exist. Feel free to send a PR!

jaawerth commented 9 years ago

Done!