@@ -1893,6 +1893,56 @@ Same as C<infix //>, except with looser precedence.
1893
1893
Returns the first defined argument, or else the last argument.
1894
1894
Short-circuits.
1895
1895
1896
+ = head1 Sequencer Precedence
1897
+
1898
+ = head2 infix C « ==> »
1899
+
1900
+ This X < pipeline > operator takes the result from the left and passes it as the
1901
+ last parameter to the right. This allows for a more natural left-to-right data
1902
+ flow similar to method chaining, but can be used with functions that are not
1903
+ methods of the data in the pipeline.
1904
+
1905
+ # Traditional structure, read bottom-to-top
1906
+ my @result =
1907
+ sort # (4) Sort, result is <Earth People>
1908
+ grep { /<[PE]>/ }, # (3) Look for P or E
1909
+ map { .tc }, # (2) Capitalize the words
1910
+ <people of earth>; # (1) Start with the input
1911
+
1912
+ # Pipeline (left-to-right), read top-to-bottom
1913
+ my @result =
1914
+ <people of earth> # (1) Start with the input
1915
+ ==> map { .tc } # (2) Capitalize the words
1916
+ ==> grep /<[PE]>/ # (3) Look for P or E
1917
+ ==> sort; # (4) Sort, result is <Earth People>
1918
+
1919
+ # For illustration, method chaning equivalent for Lists, read top-to-bottom
1920
+ my @result =
1921
+ <people of earth> # (1) Start with the input
1922
+ .map({ .tc }) # (2) Capitalize the words
1923
+ .grep(/<[PE]>/) # (3) Look for P or E
1924
+ .sort; # (4) Sort, result is <Earth People>
1925
+
1926
+ = head2 infix C « <== »
1927
+
1928
+ This X < leftward pipeline > operator takes the result from the right and passes
1929
+ it as the last parameter to the left. This makes visible the right-to-left
1930
+ dataflow for a series of list manipulating functions.
1931
+
1932
+ # Traditional structure, read bottom-to-top
1933
+ my @result =
1934
+ sort # (4) Sort, result is <Earth People>
1935
+ grep { /<[PE]>/ }, # (3) Look for P or E
1936
+ map { .tc }, # (2) Capitalize the words
1937
+ <people of earth>; # (1) Start with the input
1938
+
1939
+ # Pipeline (right-to-left), read bottom-to-top
1940
+ my @result =
1941
+ sort # (4) Sort, result is <Earth People>
1942
+ <== grep { /<[PE]>/ }, # (3) Look for P or E
1943
+ <== map { .tc }, # (2) Capitalize the words
1944
+ <== <people of earth>; # (1) Start with the input
1945
+
1896
1946
= end pod
1897
1947
1898
1948
# vim: expandtab shiftwidth=4 ft=perl6
0 commit comments