Advanced Functions

Comprehensive guide to Advanced Functions in Linea

Advanced Function Patterns

Keep functions focused and composable. Return typed values and separate side effects.

Composed Functions

func add(a: int, b: int) -> int {
    a + b
}

func weighted_sum(x: int, y: int, w: int) -> int {
    add(x * w, y)
}

display weighted_sum(3, 5, 2)

Module-style Utility Function

func clamp(v: int, lo: int, hi: int) -> int {
    if v < lo { lo }
    else if v > hi { hi }
    else { v }
}