Skip to main content

Functions and Lambdas

Functions are just let bindings that take parameters (see Bindings):

# A function binding that takes a single immutable parameter.
let function(input: i32) = ...

Parameters default to immutable, but can be marked explicitly:

let function(let immutable: i32) = ...
let function(var mutableInput: i32) = ...

Parameters can have default values:

# By default we set the created image version to "1.0.0".
let createImage(let version = "1.0.0") = ...

Lambdas​

Lambdas are anonymous functions defined with the -> arrow:

# Create a lambda function that performs a math operation on two numbers.
let maths(operation: (left: i32, right: i32) -> i32) : i32
# Call the math function with two lambdas.
let sum = maths((left, right) -> left + right)
let product = maths((left, right) -> left * right)

A shorthand exists for a lambda that always returns the same constant value:

let constant = maths(lambda(5))
let withBlock = maths(lambda { return 5 })