fREWdiculous!
17 Aug
Today I wanted to generate a list from another list. Typically I would use map for this, but I wanted to iterate over two elements at a time, instead of one at a time. (A lot of people said to use natatime from List::MoreUtils, over and over. They didn’t read my question very carefully, especially since I specifically said I wanted natatime but with map.)
Anyway, mst pointed out Perl6::Gather, which works perfectly for this situation! Ah the beauty of Perl 6 in Perl 5. Here are the codez:
1 2 3 4 5 6 7 8 9 |
So basically what that does is create an implicit accumulator and every time you call take it adds the arguments to take to the accumulator. In Perl 6 map can iterate over multiple items at once, so this would be silly in that context, but in Perl 5 it’s quite helpful!
Leave a reply