All academies
All challenges

Compose Two Functions

mediumfunctions100 XP

Problem

Write a generic compose(f, g) that returns a new function applying g first and then f, i.e. compose(f, g)(x) equals f(g(x)). Use three type parameters A, B, and C so that g maps A to B and f maps B to C, and the composed function maps A to C. The types must flow through without any casts.

Expected output

10
16

Hints

Stuck? Reveal hints one at a time.

Solution

Try solving it yourself first — revealing is always available.

Press Run in the editor — your console output is checked automatically.
No errors
Loading...

Console output appears here. Press Run or just type — the code compiles automatically.