What does Any.match do?
.match
is a search for a needle in a single haystack string. An infinite sequence stringifies to '...'
.
say (1,3 ... 9).Str; # 1 3 5 7 9
say (1,3 ... 9).match: '1'; # 「1」
say (1,3 ... *).Str; # ...
say (1,3 ... *).match: '.'; # 「.」
How I worked this out
First, you're looking at the wrong method definition:
method match(Any:U: |) { ... }
Any:U
is kinda like Any $ where not .defined
except if it matched you would get the error message "Parameter '<anon>' of routine 'match' must be a type object of type 'Any', not an object instance ...".
But you're passing a defined Seq
. So your .match
calls don't dispatch to the method definition you're looking at.
To find out what a method dispatches to, use:
say (1,3 ... *).^lookup('match').package ; # (Cool)
A defined Seq
will thus dispatch to the Cool
code:
method match(Cool:D: |c) {
...
self.Stringy.match(|c)
}
So, next:
say (1,3 ... *).^lookup('Stringy').package ; # (Mu)
And the code:
multi method Stringy(Mu:D $:) { self.Str }
So check:
say (1,3 ... *).Str; # ...
Bingo.
And confirm:
say (1,3 ... *).match: '.'; # 「.」