Files
lux/examples/pipelines.lux
2026-02-17 06:52:44 -05:00

40 lines
982 B
Plaintext

fn double(x: Int): Int = x * 2
fn addTen(x: Int): Int = x + 10
fn square(x: Int): Int = x * x
fn negate(x: Int): Int = -x
let result1 = square(addTen(double(5)))
let result2 = addTen(double(addTen(double(3))))
fn process(n: Int): Int = square(addTen(double(n)))
let a = process(1)
let b = process(2)
let c = process(3)
fn clampPositive(x: Int): Int = if x < 0 then 0 else x
let clamped = clampPositive(double(-5))
fn increment(x: Int): Int = x + 1
let composed = square(increment(double(5)))
fn printResults(): Unit with {Console} = {
Console.print("5 |> double |> addTen |> square = " + toString(result1))
Console.print("Pipeline result2 = " + toString(result2))
Console.print("process(1) = " + toString(a))
Console.print("process(2) = " + toString(b))
Console.print("process(3) = " + toString(c))
Console.print("clamped = " + toString(clamped))
Console.print("composed = " + toString(composed))
}
let output = run printResults() with {}