Functions · 2.4
Higher-Order Functions
All lessons are open — jump whenever you need.
Functions that receive or return other functions:
fn apply(f, x: int) -> int {
return f(x)
}
let result = apply(|x| x * x, 5)
print(result) // 25Goal: Implement apply_twice(f, x) that applies the function f twice. Test with a closure that adds 3, passing the value 10 — result: 16.
lesson-2-4.zolo
Program output
Run the code to see the output