Course of Raku / Advanced / Subroutines / The Whatever star 🆕 / Exercises / Whatever with map

Solution: Whatever with map

Here is a possible solution to the task.

Code

my $triple = * * 3;

say (1..4).map($triple);

🦋 You can find the source code in the file whatever-map.raku.

Output

(3 6 9 12)

Comments

  1. * * 3 is a Whatever expression that becomes a one-argument WhateverCode — a perfectly ordinary function value stored in $triple.

  2. Because it is just a function, map accepts it like any block, applying it to each element of 1..4 to give (3 6 9 12).

Course navigation

Whatever with map   |   A two-argument Whatever