// LANG-COMP-010-04: Higher-Order Functions
// Demonstrates functions that take or return closures

fn main() {
    // Function taking closure as parameter
    fn apply(f, x) {
        f(x)
    }

    let double = |n| { n * 2 }
    println(apply(double, 21))

    // Function taking multiple closure parameters
    fn compose(f, g, x) {
        f(g(x))
    }

    let add_one = |n| { n + 1 }
    let times_two = |n| { n * 2 }
    println(compose(add_one, times_two, 5))

    // Function returning closure
    fn make_counter(start) {
        |increment| { start + increment }
    }

    let counter = make_counter(10)
    println(counter(5))
    println(counter(3))
}
