thp-lang.org/md/learn/functions/higher-order.md
2023-10-01 20:41:38 -05:00

349 B

Higher Order functions

Function as parameter

fun map[A, B](Array[A] input, (A) -> B function) -> Array[B]
{
    // implementation
}

Function as return

fun generate_generator() -> () -> Int
{
    // code...
}


val generator = generate_generator()  // A function
val value = generate_generator()()    // An Int