Course of Raku / Addendum 🆕 / Flow and functions / Subroutines and functional style / Exercises

Compose two functions

Problem

Write a subroutine compose that takes two functions and returns a new function applying them one after the other — first the second, then the first. Compose “double” with “add one”, then call the result on 5 (giving 12).

Example

The program prints:

12

Solution

See the solution

Course navigation

Solution: Digit sum by recursion   |   Solution: Compose two functions