Course of Raku / Functional, concurrent, reactive, and web programming / Functional programming / Lambdas and closures / Exercises / A multiplier
Solution: A multiplier
Here is a possible solution to the task.
Code
sub multiplier($factor) {
-> $x { $x * $factor };
}
my &triple = multiplier(3);
say triple(4);🦋 You can find the source code in the file multiplier.raku.
Output
12Comments
The returned pointy block closes over
$factor, remembering it is3.Calling it with
4gives12.
Course navigation
← A multiplier | An accumulator →