Course of Raku / Functional, concurrent, reactive, and web programming / Functional programming / Lambdas and closures / Exercises

A multiplier

Problem

Write a subroutine multiplier that takes a factor and returns a closure multiplying its argument by that factor. Build a “times three” function and call it with 4.

Example

The program prints:

12

Solution

See the solution

Course navigation

Solution: A counter   |   Solution: A multiplier