First-class functions
Here we use the Z ("zipwith") metaoperator to zip the 𝐴 and 𝐵 lists with builtin composition operator, ∘ (or just o). The .() construct invokes the function contained in the $_ (current topic) variable.
my \𝐴 = &sin, &cos, { $_ ** <3/1> }
my \𝐵 = &asin, &acos, { $_ ** <1/3> }
say .(.5) for 𝐴 Z∘ 𝐵Output:
0.5
0.4999999999999999
0.5000000000000001It is not clear why we don't get exactly 0.5, here.
Operators, both builtin and user-defined, are first class too.
my @a = 1,2,3;
my @op = &infix:<+>, &infix:<->, &infix:<*>;
for flat @a Z @op -> $v, &op { say 42.&op($v) }Output:
43
40
126Last updated
Was this helpful?