Skip to content

Commit 24f42e9

Browse files
committed
Add, fix and reword feed operator docs
Update some verbiage, fix a few spelling errors, fix the examples, and add some additional examples.
1 parent 5ac95ba commit 24f42e9

File tree

1 file changed

+67
-26
lines changed

1 file changed

+67
-26
lines changed

doc/Language/operators.pod

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,10 +1897,17 @@ Short-circuits.
18971897
18981898
=head2 infix C«==>»
18991899
1900-
This X<feed> 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 each step.
1900+
This X<feed> operator takes the result from the left and passes it to the
1901+
next (right) routine as the last parameter. This allows
1902+
for a more natural left-to-right data flow similar to method chaining, but
1903+
gives you the freedom to use something other than methods directly available
1904+
to the data (the result of a bare routine or an unrelated data's method).
1905+
1906+
The precedence is very loose so you will need to use parentheses to
1907+
assign the result or you can even just use another feed operator! In the
1908+
case of routines/methods that take a single argument or the first argument
1909+
is a block, it is often required that you call with parentheses (though this
1910+
is not required for the very last routine/method).
19041911
19051912
# Traditional structure, read bottom-to-top
19061913
my @result =
@@ -1909,40 +1916,74 @@ methods of the data in each step.
19091916
map { .tc }, # (2) Capitalize the words
19101917
<people of earth>; # (1) Start with the input
19111918
1912-
# Feed (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>
1919+
# Feed (left-to-right) with parentheses, 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+
);
19181926
1919-
# For illustration, method chaning equivalent for Lists, read top-to-bottom
1927+
# For illustration, method chaining equivalent, read top-to-bottom
19201928
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>
1929+
<people of earth> # (1) Start with the input
1930+
.map({ .tc }) # (2) Capitalize the words
1931+
.grep(/<[PE]>/) # (3) Look for P or E
1932+
.sort; # (4) Sort, result is <Earth People>
1933+
1934+
# To assign without the need of parentheses use another feed operator
1935+
<people of earth>
1936+
==> map({ .tc })
1937+
==> grep /<[PE]>/
1938+
==> sort()
1939+
==> my @result;
1940+
1941+
# It can be useful to capture a partial result
1942+
<people of earth>
1943+
==> map({ .tc })
1944+
==> my @caps; @caps # also could wrap in parentheses instead
1945+
==> grep /<[PE]>/
1946+
==> sort()
1947+
==> my @result;
19251948
19261949
=head2 infix C«<==»
19271950
19281951
This X<leftward feed> 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.
1952+
it to the previous (left) routine as the last parameter. This
1953+
elucidates the right-to-left dataflow for a series of list manipulating
1954+
functions.
19311955
19321956
# 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-
# Feed (right-to-left), read bottom-to-top
19401957
my @result =
19411958
sort # (4) Sort, result is <Earth People>
1942-
<== grep { /<[PE]>/ }, # (3) Look for P or E
1943-
<== map { .tc }, # (2) Capitalize the words
1959+
grep { /<[PE]>/ }, # (3) Look for P or E
1960+
map { .tc }, # (2) Capitalize the words
1961+
<people of earth>; # (1) Start with the input
1962+
1963+
# Feed (right-to-left) with parentheses, read bottom-to-top
1964+
my @result = (
1965+
sort() # (4) Sort, result is <Earth People>
1966+
<== grep({ /<[PE]>/ }) # (3) Look for P or E
1967+
<== map({ .tc }) # (2) Capitalize the words
1968+
<== <people of earth> # (1) Start with the input
1969+
);
1970+
1971+
# To assign without parentheses, use another feed operator
1972+
my @result
1973+
<== sort() # (4) Sort, result is <Earth People>
1974+
<== grep({ /<[PE]>/ }) # (3) Look for P or E
1975+
<== map({ .tc }) # (2) Capitalize the words
19441976
<== <people of earth>; # (1) Start with the input
19451977
1978+
# It can be useful to capture a partial result
1979+
my @result
1980+
<== sort()
1981+
<== grep({ /<[PE]>/ })
1982+
<== my @caps # unlike <==, there is no need for addtl. statement
1983+
<== map({ .tc })
1984+
<== <people of earth>;
1985+
1986+
19461987
=end pod
19471988

19481989
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)