Quick actions

cmd+k|ctrl+k

Navigation

Languages

Raku SIMD Hyper Operator »

Snippet info

Language

Raku

Visibility

public

Author

221a86612c7785cb6094f25b034cba9994736288

Created

2024-05-01T08:18:37.203Z

Updated

2024-05-01T08:28:12.736184Z

use Test;

# SIMD vectorized (compiler hintend parallel) operations using "»" and "«" operators
# see https://docs.raku.org/syntax/%3C%3C
# direction of » indicates if vector gets cycled

say "no cycling";
ok        (1..3)    »+«  (1..3)     ~~ <2 4 6>,                        "addition";
ok        (1..3)    »~«  ('a'..'c') ~~ <1a 2b 3c>,                     "concat";
ok        ('a'..'c' »=>« 1..3)      ~~ ('a' => 1, 'b' => 2, 'c' => 3), "pairs, or any other operation";
dies-ok { (1..3)    »+«  (1..2)                                     }, "RHS too short";

say "only RHS cycled";
ok (1..5) »~» <a b>  ~~ <1a 2b 3a 4b 5a>;
ok (1..5) »%%» 3     ~~ <False False True False False>;

say "LHS and RHS cycled";
ok (1..3,'a'..'d') «~» (<a b>, 7..19) ~~ (<1a 2b 3a>, <a7 b8 c9 d10 a11 b12 c13 d14 a15 b16 c17 d18 a19>);

say "working also on single list-like object";
my @a = 1, 2, 3;
@a»++;
ok @a ~~ <2 3 4>, "same as: @a »+» 1, but in-place";

say "you can apply custom functions";
ok (1..3, -2..5)».&{ .abs + 1 } ~~ (2..4, <3 2 1 2 3 4 5 6>);
INFO