2 ms·
It’s kinda different although you can do some similar things. IMO the ruby one is more powerful because it effectively allows you to customize language syntax
by NegativeLatency 3y ago
It’s kinda different although you can do some similar things.
IMO the ruby one is more powerful because it effectively allows you to customize language syntax by supplying a block. And it fits nicely with the stdlib and libraries (ex map yields to a block to do the mapping). Ruby also has an enumerator that does some similar things to pythons yield: https://docs.ruby-lang.org/en/master/Enumerator.html https://docs.ruby-lang.org/en/master/Enumerator.html
Pythons yield is more commonly used for iteration and stuff although it does allow some neat tricks for scoping things.