Examples · learn/09-closures · 149 of 339
fn-values
tin run examples/learn/09-closures/fn-values.tinfn double(x: int): int => x * 2
fn square(x: int): int => x * x
// f is a function that takes an int and returns an int: its type is (int) => int
fn applyTwice(f: (int) => int, x: int): int => f(f(x))
fn main() {
print(applyTwice(double, 3))
print(applyTwice(square, 3))
let op = square // a function is a value like any other
print(op(9))
}