Course of Raku / Essentials / Functions essentials / More about functions
Return type
The result of the function can also be explicitly made typed. There are a few ways to express that in code.
sub add(Int $x, Int $y) returns Int { $x + $y }
my Int sub add(Int $x, Int $y) { $x + $y }
sub add(Int $x, Int $y) of Int { $x + $y }
sub add(Int $x, Int $y --> Int) { $x + $y }Choose one that you like the most. Notice that in the fourth example, the return type is written inside of the parentheses with function parameters.
Practice
Complete the 1 quiz that covers the contents of this topic.
Course navigation
← Quiz — Typed parameters | Quiz — Return type →
💪 Or jump directly to
the exercise to this section.