infix ==>
這個流操作符(feed operator)從它的左側接收結果并把結果作為最后一個參數傳遞給下一個(右側的)例程(routine)痰哨。
這個操作符的優(yōu)先級很松散所以你需要使用圓括號把結果賦值給其它變量, 或者你甚至可以使用另外一個流操作符! 在接收單個參數或第一個參數為 block 的程序/方法的例子中, 你必須經常使用圓括號來調用(盡管這對于最后一個例程/方法不是必須的)匾嘱。
# 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
@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
@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
<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
<people of earth>
==> map({ .tc })
==> my @caps; @caps # also could wrap in parentheses instead
==> grep /<[PE]>/
==> sort()
==> @result;
這個流操作符能讓你在例程之外構建方法鏈那樣的模式并且方法的結果能在不相關的數據上調用。在方法鏈中, 你被限制于使用數據身上可用的方法或使用之前的方法調用的結果撬讽。使用流操作符, 那個限制沒有了。寫出來的代碼比一系列用多個換行符打斷的方法調用更加可讀游昼。
注: 在將來, 這個操作符會在它獲得并行地運行列表操作的能力之后有所變化。它會強制左側的操作數作為一個閉包(它能被克隆并運行在子線程中)變得可閉合烘豌。
infix <==
這個向左的流操作符從右側接收結果并把結果作為最后的一個參數傳遞給它前面的(左側的)例程。這為一系列列表操作函數闡明了從右到左的數據流廊佩。
# 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 (right-to-left) with parentheses, read bottom-to-top
@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
);
# To assign without parentheses, use another feed operator
@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
# It can be useful to capture a partial result
@result
<== sort()
<== grep({ /<[PE]>/ })
<== my @caps # unlike ==>, there is no need for additional statement
<== map({ .tc })
<== <people of earth>;
和向右的流操作符不一樣, 這個結果不能嚴格地映射為方法鏈靖榕。然而, 和上面?zhèn)鹘y的結構中每個參數使用一行分割相比, feed 操作符寫出的代碼比逗號更具描述性。向左的流操作符也允許你打斷語句并捕獲一個可能對調試來說極其方便的中間結果或者接收那個結果并在最終結果身上創(chuàng)建另外一個變種序矩。
注意: 在將來, 這個操作符會在它獲得并行地運行列表操作的能力之后有所變化跋破。它會強制右側的操作數作為一個閉包變得可閉合(它能被克隆并運行在子線程中)