Course of Raku / Advanced / Subroutines / Calling with a colon 🆕 / Exercises / Join with a colon

Solution: Join with a colon

Here is a possible solution to the task.

Code

say <a b c>.reverse.join: '-';

🦋 You can find the source code in the file colon-join.raku.

Output

c-b-a

Comments

  1. .reverse keeps its ordinary form because it is in the middle of the chain. join comes last, so it can use the colon, passing '-' exactly as join('-') would.

  2. The list reversed to c, b, a is then joined with dashes, giving c-b-a. The colon form works with ordinary values, not only blocks.

Course navigation

Join with a colon   |   Sort with a colon