What is the raku equivalent of the JavaScript arrow function?

Viewed 223
1 Answers

The most direct equivalent would be

my @materials = <Hydrogen Helium Lithium Beryllium>;
say @materials.map(-> $material { $material.chars });

but an arrow sub is more explicit than you need in this case, because

say @materials.map: *.chars;

would also be sufficient (method call on a "whatever star" returns a code block that calls that method on its argument), and

say @materials».chars;

would also work (hyper-application applied to the dot operator).

Related