Course of Raku / Advanced / Subroutines / The Whatever star 🆕 / Exercises / A two-argument Whatever

Solution: A two-argument Whatever

Here is a possible solution to the task.

Code

my $join = * ~ '-' ~ *;

say $join('a', 'b');

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

Output

a-b

Comments

  1. The expression contains two stars, so Raku builds a WhateverCode that takes two arguments — the first star is the first argument, the second star is the second.

  2. Calling $join('a', 'b') fills the stars in order, giving 'a' ~ '-' ~ 'b', which is a-b.

Course navigation

A two-argument Whatever   |   An open-ended range