I don't really see a win with this style, though, over giving test a parameter, and just using standard function calls (I had a little play with coroutines on the way but that's really overkill for this).def rubyyielder(gen): def wrapped_gen(block): for elem in gen(): block(elem) return wrapped_gen @rubyyielder def test(): print("In test") yield 1 print("back in test") yield 2 @test def _(a): print("You are in block %s" % a)
In reply to Re^5: RFC: Simulating Ruby's "yield" and "blocks" in Perl (Python)
by MonkOfAnotherSect
in thread RFC: Simulating Ruby's "yield" and "blocks" in Perl
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |