Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 674 Bytes

File metadata and controls

39 lines (28 loc) · 674 Bytes

Lambda Functions (Anonymous Functions) λ

Lambdas are values that represent functions. They are defined using the -> (arrow) operator.

Syntax

  • (a, b) -> expression (Single expression return)
  • (a) -> { ... } (Multi-statement block)
  • async (a, b) -> { ... } (Asynchronous lambda)

Examples

Basic Lambda

let add = (a, b) -> a + b
let result = add(5, 10)

Passing to Functions

fn runCallback(cb) {
    cb()
}

runCallback(() -> {
    print("Callback executed!")
})

Async Lambda

let fetchData = async () -> {
    const (data, err) = await Network.get("https://api.example.com");
    return data;
}