Skip to content

Commit 775f029

Browse files
committed
Add documentation for pipeline operators
I left out ==>> and <<== since they are not implemented in Rakudo.
1 parent dcd7218 commit 775f029

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

doc/Language/operators.pod

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,56 @@ Same as C<infix //>, except with looser precedence.
18931893
Returns the first defined argument, or else the last argument.
18941894
Short-circuits.
18951895
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+
18961946
=end pod
18971947

18981948
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)