3 ms·
For list comprehensions and a different style of generator, look at https://metacpan.org/module/List::Gen https://metacpan.org/module/List::Gen And then there
by hercynium 14y ago
For list comprehensions and a different style of generator, look at https://metacpan.org/module/List::Gen https://metacpan.org/module/List::Gen
And then there are a pile of modules that implement python-style generators, some using https://metacpan.org/module/Coro https://metacpan.org/module/Coro (co-routines implemented as threads), some using crazy hacks:
https://metacpan.org/module/Compile::Generators https://metacpan.org/module/Compile::Generators
https://metacpan.org/module/Coro::Generator https://metacpan.org/module/Coro::Generator
https://metacpan.org/module/Attribute::Generator https://metacpan.org/module/Attribute::Generator
- ajross 14y agoYeah, honestly though those fail the "clean" test for me. What I really meant isn't the computational capabilities of python generators but the way the mesh nicely with the way builtins like "in" or "all()" or "any()" work on plain old data. Reasoning about them, in general, isn't any harder than reasoning about a dict or list in the common case, and that's a feature missing from the perl equivalents which try to do it in a library. I'd feel comfortable throwing a comprehension into code intended to be maintained by a novice. I'd never inflict any of that junk on the poor maintainer.