3 ms·
Partly related but generators clicked for me when I heard them described as, "instead of pushing data into a function, you're pulling results out of a function.
by Waterluvian 8y ago
Partly related but generators clicked for me when I heard them described as, "instead of pushing data into a function, you're pulling results out of a function."
I've been doing a lot of asyncio lately and just having a mental model of my pipelines working by pulling results through them has been invaluable.
- pault 8y agoBut you're also pushing data back in. Generators are coroutines that can be suspended and resumed, and the yield keyword is a mechanism for two way communication between the routine and coroutine.
- Waterluvian 8y agoTrue. The idea doesn't hold as well now that data can be passed into a generator in Python. Ie. Now that there's coroutines.