style: auto-format example files with lux fmt
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,47 +1,31 @@
|
||||
// Demonstrating the pipe operator and functional data processing
|
||||
//
|
||||
// Expected output:
|
||||
// 5 |> double |> addTen |> square = 400
|
||||
// Pipeline result2 = 42
|
||||
// process(1) = 144
|
||||
// process(2) = 196
|
||||
// process(3) = 256
|
||||
// clamped = 0
|
||||
// composed = 121
|
||||
|
||||
// Basic transformations
|
||||
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
|
||||
|
||||
// Using the pipe operator for data transformation
|
||||
let result1 = 5 |> double |> addTen |> square
|
||||
let result1 = square(addTen(double(5)))
|
||||
|
||||
// Chaining multiple operations
|
||||
let result2 = 3 |> double |> addTen |> double |> addTen
|
||||
let result2 = addTen(double(addTen(double(3))))
|
||||
|
||||
// More complex pipelines
|
||||
fn process(n: Int): Int =
|
||||
n |> double |> addTen |> square
|
||||
fn process(n: Int): Int = square(addTen(double(n)))
|
||||
|
||||
// Multiple values through same pipeline
|
||||
let a = process(1)
|
||||
|
||||
let b = process(2)
|
||||
|
||||
let c = process(3)
|
||||
|
||||
// Conditional in pipeline
|
||||
fn clampPositive(x: Int): Int =
|
||||
if x < 0 then 0 else x
|
||||
fn clampPositive(x: Int): Int = if x < 0 then 0 else x
|
||||
|
||||
let clamped = -5 |> double |> clampPositive
|
||||
let clamped = clampPositive(double(-5))
|
||||
|
||||
// Function composition using pipe
|
||||
fn increment(x: Int): Int = x + 1
|
||||
|
||||
let composed = 5 |> double |> increment |> square
|
||||
let composed = square(increment(double(5)))
|
||||
|
||||
// Print results
|
||||
fn printResults(): Unit with {Console} = {
|
||||
Console.print("5 |> double |> addTen |> square = " + toString(result1))
|
||||
Console.print("Pipeline result2 = " + toString(result2))
|
||||
|
||||
Reference in New Issue
Block a user