|
|
|
|
|
by listcomp
4913 days ago
|
|
That can't, but with https://gist.github.com/605891 you can, using syntax like: [(1..6),(4..6),(7..9)].comprehension { |a, b, c| a + b + c if a % 2 == 0 }
And if you go to extremes like https://gist.github.com/3356675 you can use Haskell-like syntax: [a + b | a <- ['n','p'..'t'], b <- %w[a i u e o]]
Ruby's blocks and method_missing are very powerful. |
|
NB. Correction to my earlier comment elsewhere here about List::Gen & multiple lists because it does provide cross combinators and also gather/take which is a perl6 way of doing complicated (multi) list comprehensions.
Here are the two examples written in perl6 (which do work in Rakudo).