Woo! Very basic lambdas!
This commit is contained in:
25
tests/test_lambda.krak
Normal file
25
tests/test_lambda.krak
Normal file
@@ -0,0 +1,25 @@
|
||||
import io:*
|
||||
|
||||
fun runLambda(func: fun():int):void {
|
||||
println(func())
|
||||
}
|
||||
|
||||
fun callLambda(func: fun(int):void):void {
|
||||
func(10)
|
||||
}
|
||||
|
||||
fun itr<T>(it: T, func: fun(T):T):T {
|
||||
println(it)
|
||||
return func(it);
|
||||
}
|
||||
|
||||
fun main():int {
|
||||
var func = fun():void { println("8"); }
|
||||
func()
|
||||
runLambda(fun():int { return 9;})
|
||||
callLambda(fun(a:int):void { println(a);})
|
||||
var j = 0
|
||||
while (j < 10) j = itr(j, fun(a:int):int { return a+1; })
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user