Version: 1.1.0

Lambda expressions

A lambda is a short function expression. It is useful as an argument and awkward as a program's main structure.

Essentials

  • The form is lambda args: expression.
  • Types can be written when inference is not enough.
  • A lambda captures surrounding names the same way a nested function does.
  • Use a nested fn once the body needs statements.

Example

def main():
    var twice = lambda n: n * 2
    print(twice(21))

Keep in mind

Lambdas do not replace def. They only remove ceremony for a single expression.