Skip to content

Instantly share code, notes, and snippets.

@taboege
Created May 29, 2019 12:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save taboege/53fc512a05b86a4934df4900eea119f7 to your computer and use it in GitHub Desktop.
Add smartmatch to an enum
#!/usr/bin/env perl6
enum Keyword «a b c»;
class C {
has %.keywords;
}
my $c = C.new: :keywords{(a) => True};
Keyword.^add_multi_method("ACCEPTS", anon method (Keyword:D: C \c) {
c.keywords{self}:exists
});
Keyword.^compose;
say $c ~~ a;
say $c ~~ b;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment