September 2017
Beginner
402 pages
9h 52m
English
The reduction operator [op], when applied to a list, executes the op operation for every subsequent pair of elements. In other words, the list is enrolled and the op symbol is inserted between them.
Let's examine the meta-operator in the following example:
my @a = (1, 2, 3);say [+] @a; # 6
A [+] @a expression is equivalent to the following one:
say @a[0] + @a[1] + @a[2];
Let's take a look at another example—[*]. This meta-operator can be used to calculate factorials:
say [*] 1..5; # 120Read now
Unlock full access