infix ∘

Documentation for infix assembled from the following types:

language documentation Operators

From Operators

(Operators) infix ∘

multi sub infix:<>()
multi sub infix:<>(&f)
multi sub infix:<>(&f&g --> Block:D)

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 slipped into the left function.

Both .count and .arity of the right-hand side will be maintained.

sub f($p){ say 'f'$p / 2 }
sub g($p){ say 'g'$p * 2 }
my &composed = &f  &g;
say composed 2# OUTPUT: «g␤f␤2␤» 
# equivalent to: 
say 2.&g.&f;
# or to: 
say f g 2;
sub f($a$b$c{ [~$c$b$a }
sub g($str){ $str.comb }
my &composed = &f  &g;
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 &composed = [&uc;
say composed 'foo'# OUTPUT: «FOO␤» 
my &composed = [];
say composed 'foo'# OUTPUT: «foo␤»