Skip to content

Instantly share code, notes, and snippets.

@grondilu
Last active December 17, 2015 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grondilu/5544948 to your computer and use it in GitHub Desktop.
Save grondilu/5544948 to your computer and use it in GitHub Desktop.
combinations method for Array
use MONKEY_TYPING;
augment class Array {
method combinations(Int $of) {
return [] if $of == 0;
return () if self.elems == 0;
map({ [ self[0], $_[] ] }, [self[1..*-1]].combinations($of-1)),
[self[1..*-1]].combinations( $of );
}
}
my @a = ^5;
say .perl for @a.combinations: 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment