1, 2, 4 ... 32; # 1 2 4 8 16 32 1, 2, 4 ... * > 10; # 1 2 4 8 16
# 'when': given $age { when 100 { say "!" } when * < 18 { say " " } } # 'where': subset Even of Int where * %% 2; # smartmatch: if $input ~~ m/^\d+$/ { say "$input – "; } # grep(), first() ..: my @even = @numbers.grep: Even;
# Str? $foo ~~ Str # 6? $foo ~~ 6 # "bar"? $foo ~~ "bar" # ? $foo ~~ / \w+ '-' \d+ / # 15 25? $foo ~~ (15..25) # $foo ~~ -> $x { say 'ok' if 5 < $x < 25 } # 6 , 1? $foo ~~ [1, *, 1, *, 1, *]
class Point { has $.x; has $.y; method ACCEPTS(Positional $p2) { return $.x == $p2[0] and $.y == $p2[1] } }
my $a = Point.new(x => 7, y => 9); say [3, 5] ~~ $a; # Bool::False say (7, 9) ~~ $a; # Bool::True
Source: https://habr.com/ru/post/254029/
All Articles