September 2017
Beginner
402 pages
9h 52m
English
Hyper-operators in Perl 6 apply the operation to each element of the list operand. They work with both unary and binary operators and use the << and >> symbols, and their synonyms, « and ».
Let's explore hyper-operators with examples:
my @a = 1..10;@a = @a <<+>> 3;say @a; # [4 5 6 7 8 9 10 11 12 13]
In this first example, the value of 3 is added to each element of the @a array. On the left side of the <<+>> hyper-operator is an array with ten elements. On the right side, we have a scalar value. This value is added to all elements of the array on the left.
In this example, the same <<+>> operator is used with two arrays of the same length:
my @x = (1, 2, 3);my @y = (4, 5, 6);say @x <<+>> @y; # [5 7 9]
The result is a new array ...
Read now
Unlock full access