Invocable code object
Callables can be stored in
&-sigiled containers, the default type constraint of such a container is
Callable. A signature object can be used to force a check against the signature of the Callable to be stored into the container.
my = ; # Empty block needs a semicolonmy = -> ;my = sub () ;sub foo() ;my = ;
my :(Int) = sub bar(Int) ; # Not yet implementedmy :(Str) = -> Str ; # Not yet implemented
method CALL-ME(Callable : |arguments)
This method is required for postfix:«( )» and postfix:«.( )». It's what makes an object actually call-able and needs to be overloaded to let a given object act like a routine. If the object needs to be stored in a
&-sigiled container, is has to implement Callable.
does Callablemy = A;say a(); # OUTPUT: «called␤»
method assuming(Callable : |primers)
Callable that implements the same behaviour as the original, but has the values passed to .assuming already bound to the corresponding parameters.
my sub slow();# takes only one parameter and as such wont forward $nsub bench();say .assuming(10000000).; # OUTPUT: «(10000000 7.5508834)␤»
The function composition operator
infix:<o> combines two functions, so that the left function is called with the return value of the right function. If the
.count of the left function is more than 1, the return value of the right function will be slipped into the left function.
sub f()sub g()my = ∘ ;say composed 2; # OUTPUT: «g␤f␤2␤»# equivalent to:say 2..;# or to:say f g 2;
sub f(, , )sub g()my = ∘ ;say composed 'abc'; # OUTPUT: «cba␤»# equivalent to:say f |g 'abc';