Last active
May 30, 2017 01:35
-
-
Save zengargoyle/5a14f01a35918f6c3391b90e9b85a22a to your computer and use it in GitHub Desktop.
* ~~ /<$match> vs -> $x { $x ~~ /<$match>/ }
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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