Documentation for sub lastcall

Documentation for sub lastcall, assembled from the following types:

class Method

From Method

(Method) sub lastcall

sub lastcall(--> True)

Truncates the current dispatch chain, which means any calls to nextsame, callsame, nextwith, and callwith will not find any of the next candidates. Note that since samewith restarts the dispatch from the start, it's not affected by the truncation of current chain with lastcall.

Consider example below. foo(6) uses nextsame when lastcall hasn't been called, and so it reaches the Any candidate. foo(2) calls nextsame as well, but since lastcall was called first, the dispatch chain was truncated and the Any candidate was not reached. The last call, foo(1), calls lastcall too, however, it then uses samewith, which isn't affected by it, and so the dispatch re-starts from scratch, hits the Int candidate with the new argument 6, and then proceeds to the Any candidate via nextsame (which isn't affected by the lastcall that was used before the samewith was called):

multi foo (Int $_{
    say "Int: $_";
    lastcall   when *.is-prime;
    nextsame   when *  %% 2;
    samewith 6 when * !%% 2;
multi foo (Any $x{ say "Any $x" }
foo 6say '----';
foo 2say '----';
foo 1;
# Int: 6 
# Any 6 
# ---- 
# Int: 2 
# ---- 
# Int: 1 
# Int: 6 
# Any 6