Skip to content

Instantly share code, notes, and snippets.

@zengargoyle
Last active May 30, 2017 01:35
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 zengargoyle/5a14f01a35918f6c3391b90e9b85a22a to your computer and use it in GitHub Desktop.
Save zengargoyle/5a14f01a35918f6c3391b90e9b85a22a to your computer and use it in GitHub Desktop.
* ~~ /<$match> vs -> $x { $x ~~ /<$match>/ }
my @files = <foo bar baz>;
my @match-eq = <foo bar baz>.map( -> $s { * eq $s } ); # OK
my @match-rx = <foo ^ba>.map( -> $r { * ~~ /<$r>/ } ); # NOT OK
my @match-rx-pointy = <foo ^ba>.map( -> $r { -> $x { $x ~~ /<$r>/ } } ); # OK
sub match-it (@files, @matchers) {
return gather for @files -> $f {
take $f if @matchers.grep({ $_($f) });
}
}
say match-it(@files, @match-eq);
# output: (foo bar baz)
say match-it(@files, @match-rx);
# output: (bar baz)
# only matches the last matcher of the list,
# i.e. using <^ba foo> will output (foo)
say match-it(@files, @match-rx-pointy);
# output: (foo bar baz)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment