// 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 // Chaining multiple operations let result2 = 3 |> double |> addTen |> double |> addTen // More complex pipelines fn process(n: Int): Int = n |> double |> addTen |> square // 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 let clamped = -5 |> double |> clampPositive // Function composition using pipe fn increment(x: Int): Int = x + 1 let composed = 5 |> double |> increment |> square // Print results 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 {}