Course of Raku / Advanced / Subroutines / Calling with a colon 🆕 / Exercises / A colon map
Solution: A colon map
Here is a possible solution to the task.
Code
say (1..10).map(* * 2).grep: * > 10;🦋 You can find the source code in the file colon-map.raku.
Output
(12 14 16 18 20)Comments
Only
grep, the last call in the chain, can use the colon form. The colon makes* > 10its argument, exactly asgrep(* > 10)would. As we still need to print the results,sayis now used as a function, not as a method.The
mapcall must keep its parentheses. If you wrote.map: * * 2instead, the colon would swallow.grep(* > 10)as part ofmap’s arguments, and the chain would break.
Course navigation
← A colon map | Join with a colon →