Skip to content

Commit

Permalink
Improve doc of postfix:<.+> and postfix:<.*>
Browse files Browse the repository at this point in the history
  • Loading branch information
tisonkun committed Apr 22, 2018
1 parent 113ab80 commit b2bda56
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions doc/Language/operators.pod6
Expand Up @@ -637,19 +637,39 @@ Technically, not a real operator; it's syntax special-cased in the compiler.
X«|postfix .+»
=head2 postfix C«.+»
C<$invocant.+method> calls all methods called C<method> from C<$invocant>,
and returns a L<List> of the results. Dies if no such method was found.
C<$foo.+meth> walks the MRO and calls all the methods called C<meth> and submethods called C<meth> if the type is the same as type of C<$foo>.
Those methods might be multies, in which case the matching candidate
would be called.
Technically, not a real operator; it's syntax special-cased in the compiler.
After that, a L<List> of the results are returned. If no such method was found,
it throws a L<X::Method::NotFound> exception.
class A {
method foo { say "from A"; }
}
class B is A {
multi method foo { say "from B"; }
multi method foo(Str) { say "from B (Str)"; }
}
class C is B is A {
multi method foo { say "from C"; }
multi method foo(Str) { say "from C (Str)"; }
}
say C.+foo; # OUTPUT: «from C␤from B␤from A␤(True True True)␤»
X«|postfix .*»
=head2 postfix C«.*»
C<$invocant.*method> calls all methods called C<method> from C<$invocant>,
and returns a L<List> of the results. If no such method was found, an empty
L<List> is returned.
C<$foo.*meth> walks the MRO and calls all the methods called C<meth> and submethods called C<meth> if the type is the same as type of C<$foo>.
Those methods might be multies, in which case the matching candidate
would be called.
Technically, not a real operator; it's syntax special-cased in the compiler.
After that, a L<List> of the results are returned. If no such method was found,
an empty L<List> is returned.
Technically, postfix C<.+> calls C<.*> at first. Read postfix C<.+> section to
see examples.
X<|postfix ».>X«|postfix >>.»
=head2 postfix C<».> / postfix C«>>.»
Expand Down

0 comments on commit b2bda56

Please sign in to comment.