nvie / itertools

TypeScript port of Python's awesome itertools stdlib.
https://www.npmjs.com/package/itertools
MIT License
154 stars 20 forks source link

Operating on async-iterables #850

Open jbriales opened 1 year ago

jbriales commented 1 year ago

It seems the helpers in this package do not work when run on async-iterables. E.g. the following will complain about missing iterable[Symbol.iterator]?

Uncaught TypeError: iterable[Symbol.iterator] is not a function

Is the lack for support for async-iterables a known issue? Maybe the documentation should state this?

Also, is this just a matter of extending the logic to deal with the specifics of the async-iterables vs normal iterables? Or is there a deeper constraint/issue here preventing support for those?

nvie commented 1 year ago

Is the lack for support for async-iterables a known issue?

Yes, it's a known thing, unfortunately. In JavaScript, a sync and async iterator are different beasts, and you need to write a different version of the async one. (Much like you cannot fix and match sync/async functions in JS.)

Or is there a deeper constraint/issue here preventing support for those?

This library just doesn't support async iterables right now, but it could if support for them was added. It would basically mean that all the existing functions would have to be duplicated, and perhaps exposed as asyncMap, asyncFilter, etc.