Documentation for 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.

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).

# Traditional structure, read bottom-to-top 
my @result =
    sort                # (4) Sort, result is <Earth People> 
    grep { /<[PE]>/ },  # (3) Look for P or E 
    map { .tc },        # (2) Capitalize the words 
    <people of earth>;  # (1) Start with the input 
 
# Feed (left-to-right) with parentheses, read top-to-bottom 
my @result = (
    <people of earth>   # (1) Start with the input 
    ==> map({ .tc })    # (2) Capitalize the words 
    ==> grep /<[PE]>/   # (3) Look for P or E 
    ==> sort            # (4) Sort, result is <Earth People> 
);
 
# For illustration, method chaining equivalent, read top-to-bottom 
my @result =
    <people of earth>   # (1) Start with the input 
    .map({ .tc })       # (2) Capitalize the words 
    .grep(/<[PE]>/)     # (3) Look for P or E 
    .sort;              # (4) Sort, result is <Earth People> 
 
# 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).