Declaring lambdas
Declaring a simple lambda
The simple lambda consists of only a single statement. It will automatically return the result of said statement without the need of the put keyword.
Example
var add = {x,y => x + y}
add(2,2) //this would return 4Declaring a complex lambda
A complex lambda contains multiple LOC and does require the use of the put keyword to return things.
Example
var pow = { x,y =>
var result = 1
while(y not 0)
result *= x
y--
end
put result //complex lambda needs a put statement
}
pow(4,2) //this would return 16Lambda return types
Lambdas can state return and input types like so: lambda::(input types)->return type.
Declaring a lambda without parameters
If no parameter is needed, an _ is used as the parameter name, instead.
Example
Assigning a function to a lambda variable
One can assign a function to a lambda. If the function has function guards, they are being rewritten into a match block internally. This can be useful when passing a function to a method.
Example
Last updated