observablehq / stdlib

The Observable standard library.
https://observablehq.com/@observablehq/standard-library
ISC License
966 stars 83 forks source link

Deprecate generator transforms? #32

Open mbostock opened 6 years ago

mbostock commented 6 years ago

We currently provide two utility methods for creating a new Generator from an iterator: Generators.filter and Generators.map. There are a few problems with these methods:

  1. If the input iterator is a Generator, the returned Generator does not wrap generator.return and generator.throw. Possibly, these methods should return an Iterator rather than a Generator, and be moved to Iterators.filter and Iterators.map. Or, these methods could “upgrade” an iterator to a generator, and wrap the return and throw methods as expected.

  2. If the input iterator iterates over promises, the generator doesn’t wait for the promise to resolve. Coming from Observable, we somewhat expect the test or transform functions to be passed resolved values rather than Promise objects. However, in the case of Generators.filter, it’s not clear how that should work, since the test function might return false for the last promise, but it’s too late because the generator has already yielded a promise!

  3. If the input iterator is an async iterator (i.e., iterator.next returns a Promise), these methods don’t work at all.

It’s possible that the simplest thing to do would be to deprecate these methods along with the deprecated DOM methods #31. I haven’t found them especially useful, and given the desire to keep the standard library small, it might be good to prune them.