Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can also think of generators as a native implementation of Observables from rx (except you can't replay a generator), especially async generators.

You can implement basic operators like map, filter, take, etc. over generators to create pipelines of operations. Very neat abstraction to work with, but like rx, can quickly get hard to reason about.

Recently I wrote some tooling to read, do some operations, and write hundreds of thousands of files locally. Using generators solved having to think about not loading too much stuff into memory since it only yields files when consumed. Also allows you simply implement stuff like batching, like running X requests to a server at a time, and only starting the next batch once the first one is done.



Observables and Generators (iterators) are fundamentally different. Observables are push-based (like a promise) whereas iterators are pull-based (like a function).

Glossing over this fact leads to a flawed understanding, not a deeper one.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: