infix ==>

Documentation for infix ==> assembled from the following types:

language documentation Operators

From Operators

(Operators) infix ==>

This feed operator takes the result from the left and passes it to the next (right) routine as the last parameter.

my @array = (12345);
@array ==> sum() ==> say();   # OUTPUT: «15␤» 

This simple example, above, is the equivalent of writing:

my @array = (12345);
say(sum(@array));             # OUTPUT: «15␤» 

Or if using methods:

my @array = (12345);
@array.sum.say;               # OUTPUT: «15␤» 

The precedence is very loose so you will need to use parentheses to assign the result or you can even just use another feed operator! In the case of routines/methods that take a single argument or where the first argument is a block, it's often required that you call with parentheses (though this is not required for the very last routine/method).

This "traditional" structure, read bottom-to-top, with the last two lines creating the data structure that is going to be processed

my @fractions = <TWO THREE FOUR FIVE SEVEN> »~» " " X~ <FIFTHS SIXTHS EIGHTHS>;
my @result = map { .uniparse },                    # (3) Converts to unicode 
    grep { .uniparse },                            # (2) Checks if it parses 
    map{"VULGAR FRACTION " ~ $^þ }@fractions); # (1) Adds string to input 
 
# @result is [⅖ ⅗ ⅜ ⅘ ⅚ ⅝ ⅞] 

Now we use the feed operator (left-to-right) with parentheses, read top-to-bottom

my @result = (
    <TWO THREE FOUR FIVE SEVEN> »~» " " X~ <FIFTHS SIXTHS EIGHTHS> # (1) Input 
    ==> map{"VULGAR FRACTION " ~ $^þ } )                         # (2) Converts to Unicode name 
    ==> grep({ .uniparse })                                        # (3) Filters only real names 
    ==> map{ .uniparse} );                                       # (4) Converts to unicode 
);

For illustration, method chaining equivalent, read top-to-bottom, using the same sequence as above

my @result = ( <TWO THREE FOUR FIVE SEVEN> »~» " " X~ <FIFTHS SIXTHS EIGHTHS>)
    .map{"VULGAR FRACTION " ~ $^þ } )
    .grep({ .uniparse })
    .map({ .uniparse });

Although in this particular case the result is the same, the feed operator ==> more clearly shows intent with arrow pointing in the direction of the data flow. To assign without the need of parentheses use another feed operator

my @result;
<people of earth>
    ==> map({ .tc })
    ==> grep /<[PE]>/
    ==> sort()
    ==> @result;

It can be useful to capture a partial result, however, unlike the leftward feed operator, it does require parentheses or a semicolon

my @result;
<people of earth>
    ==> map({ .tc })
    ==> my @caps@caps   # also could wrap in parentheses instead 
    ==> grep /<[PE]>/
    ==> sort()
    ==> @result;

The feed operator lets you construct method-chaining-like patterns out of routines and the results of methods on unrelated data. In method-chaining, you are restricted to the methods available on the data or the result of previous method call. With feed operators, that restriction is gone. The resulting code could also be seen to be more readable than a series of method calls broken over multiple lines.

Note: In the future, this operator will see some change as it gains the ability to run list operations in parallel. It will enforce that the left operand is enclosable as a closure (that can be cloned and run in a subthread).