See Original text in context
multi sub infix:<o>()multi sub infix:<o>()multi sub infix:<o>(, --> Block)
The function composition operator infix:<∘>
or 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 greater than 1, the return value of the right function will be Slip into the left function.
Both .count
and .arity
of the right-hand side will be maintained, as well as the .of
of the left hand side.
sub f()sub g()my = ∘ ;say composed 2; # OUTPUT: «gf2»# equivalent to:say 2..;# or to:say f g 2;say .arity; # OUTPUT: «1»say .count; # OUTPUT: «1»say .of; # OUTPUT: «(Mu)»
sub f(, , )sub g()my = ∘ ;say composed 'abc'; # OUTPUT: «cba»# equivalent to:say f |g 'abc';
The single-arg candidate returns the given argument as is. The zero-arg candidate returns an identity routine that simply returns its argument.
my = [∘] ;say composed 'foo'; # OUTPUT: «FOO»my = [∘];say composed 'foo'; # OUTPUT: «foo»