3 ms·
> It's my favorite trick in python and I miss it dearly in other languages. Which other languages? Generator support is common: https://en.m.wikipedia.org/wik
by dragonwriter 5y ago
> It's my favorite trick in python and I miss it dearly in other languages.
Which other languages? Generator support is common:
https://en.m.wikipedia.org/wiki/Generator_(computer_programming)#Timeline https://en.m.wikipedia.org/wiki/Generator_(computer_programm...
- cogman10 5y agoThis list really sort of stretches the imagination on what language level generator support looks like. Certainly in Java you can use the `Iterator` interface to get generator like behavior. But that's both a whole lot more complex and more verbose. Primarily because you have to coordinate the `hasNext` method with the `next` method. With python and yield syntax, that naturally falls out without a bunch of extra code juggling.
- dragonwriter 5y agoSure, some of those (C, Java, C++ templates) are pretty weak, but C#, Ruby, ES6, and lots of the other language or library implementations are not. Its far from a unique Python feature.
- erik_seaberg 5y agoJava methods like Stream#filter and Stream#flatMap are easier than rolling your own iterator; you can even ask that work be done in parallel.
- tromp 5y ago"In Haskell, with its lazy evaluation model, everything is a generator"