Core Intermediate

09  Closures

A closure is a small anonymous function that can capture variables from its surroundings. Return one from a function, then accept one as an argument -- the two shapes iterator chains are built from.

Step 2 / 2

Implement apply_twice: call the closure on x, then on the result.

Hints
  • Call a closure argument like any function: f(x).
  • Twice means feeding the result back in: f(f(x)).
09_closures.rs
Reset to starterCompiled in a sandbox; hidden checks must pass.
Reveal solution
fn apply_twice(f: impl Fn(i32) -> i32, x: i32) -> i32 {
    f(f(x))
}