compose
apply-twice applied the same function twice. compose generalizes this: apply two different functions in sequence.
compose(f)(g)(x) applies g first, then f to the result. So compose(double)(add1)(4) adds 1 to get 5, then doubles to get 10.
You’ve already written apply-twice, which has two nested lambdas and a nested function call. compose adds one more lambda — it takes f, g, and x each one at a time. Three nested lambdas, three closures.
The body is the same kind of nesting you used in apply-twice: a call inside a call. But now the outer call uses a different function than the inner call.
Look at the tests carefully. compose(double)(add1) applied to 4 gives 10, but compose(add1)(double) applied to 4 gives 9. The first argument to compose runs last. Why?