Documentation for infix ==>
assembled from the following pages:
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 = (1, 2, 3, 4, 5); ==> sum() ==> say(); # OUTPUT: «15»
This simple example, above, is the equivalent of writing:
my = (1, 2, 3, 4, 5);say(sum()); # OUTPUT: «15»
Or if using methods:
my = (1, 2, 3, 4, 5);.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 = <TWO THREE FOUR FIVE SEVEN> »~» " " X~ <FIFTHS SIXTHS EIGHTHS>;my = map , # (3) Converts to unicode grep , # (2) Checks if it parses map( , ); # (1) Adds string to input # @result is [⅖ ⅗ ⅜ ⅘ ⅚ ⅝ ⅞]
Now we use the feed operator (left-to-right) with parentheses, read top-to-bottom
my = ( <TWO THREE FOUR FIVE SEVEN> »~» " " X~ <FIFTHS SIXTHS EIGHTHS> # (1) Input ==> map( ) # (2) Converts to Unicode name ==> grep() # (3) Filters only real names ==> map( ); # (4) Converts to unicode );
For illustration, method chaining equivalent, read top-to-bottom, using the same sequence as above
my = ( <TWO THREE FOUR FIVE SEVEN> »~» " " X~ <FIFTHS SIXTHS EIGHTHS>) .map( ) .grep() .map();
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 ;<people of earth> ==> map() ==> grep /<[PE]>/ ==> sort() ==> ;
It can be useful to capture a partial result, however, unlike the leftward feed operator, it does require parentheses or a semicolon
my ;<people of earth> ==> map() ==> my ; # also could wrap in parentheses instead ==> grep /<[PE]>/ ==> sort() ==> ;
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).