All subsets of a list in Perl 6

  • A+
Category:Languages

I wonder (remembering that Perl 6 has everything you could wish), whether there are some built-in instruments that can help to produce all the non-empty subsets (order doesn't matter) of a list.

E.g., I have a list:

my @a = 1, 2, 3; 

I need a function f so that f(@a) will produce:

((1), (2), (3), (1, 2), (1, 3), (2, 3), (1, 2, 3)) 


@a.combinations(1..*) 

will return the Seq you're looking for. Note that without the argument, an empty list would be generated as first element.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: