Raku By Example
View me onGitHub
## andthen

sub all-dimensions (% (:length(:$x), :width(:$y), :depth(:$z))) {
    sx andthen $y andthen $z andthen True
}

# andthen 返回第一个未定义的值, 否则返回最后一个元素。短路操作符。
# andthen 左侧的结果被绑定给 $_ 用于右侧, 或者作为参数传递, 如果右侧是一个 block 或 pointy block 的话。

## custom operator

sub postfix:<!>($n where $n > 0) {
   [*] 2..$n
}
say 5!;

constant fact = 1, [\*] 1..*;
say fact[5];

## flip

for 1..20 {.say if $_==9 ff   $_==16}
for 1..20 {.say if $_==9 ^ff  $_==16}
for 1..20 {.say if $_==9 ff^  $_==16}
for 1..20 {.say if $_==9 ^ff^ $_==16}

## with

my $s = "aabbc";
with   $s.index("a") {"Found a at $_".say}
orwith $s.index("b") {"Found b at $_".say}
orwith $s.index("c") {"Found c at $_".say}
else                 {"Didn't find a, b or c".say}