What you're searching for is the outer product. Following code should do it, and works in current Pugs :)
use v6; sub outer(*@vals) { my &helper = -> @prev, @rest { if @rest { # We've still got a rest to interate over. # We add all items of @rest[0] to the new @prev # in our sub-helper, and use @rest[1...] as new # rest, i.e. all elements of @rest except the # first one. helper [ *@prev, $_ ], @rest[1...] for @rest[0]; } else { # We don't have to recurse further, so we # simply "return" @prev. take @prev; } }; # @prev: Empty array # @rest: @vals gather { helper [], @vals }; } my @a = outer [1,2,3],[4,5,6],[7,8,9]; say join "\n", @a; # 1 4 7 # 1 4 8 # [...] # 3 6 8 # 3 6 9
--Ingo
In reply to Re: Perl6 Contest #2: P6 That Doesn't Look Like P5
by iblech
in thread Perl6 Contest #2: P6 That Doesn't Look Like P5
by Limbic~Region
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |