style: auto-format example files with lux fmt
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,31 +1,7 @@
|
||||
// Demonstrating built-in effects in Lux
|
||||
//
|
||||
// Lux provides several built-in effects:
|
||||
// - Console: print and read from terminal
|
||||
// - Fail: early termination with error
|
||||
// - State: get/put mutable state (requires runtime initialization)
|
||||
// - Reader: read-only environment access (requires runtime initialization)
|
||||
//
|
||||
// This example demonstrates Console and Fail effects.
|
||||
//
|
||||
// Expected output:
|
||||
// Starting computation...
|
||||
// Step 1: validating input
|
||||
// Step 2: processing
|
||||
// Result: 42
|
||||
// Done!
|
||||
fn safeDivide(a: Int, b: Int): Int with {Fail} = if b == 0 then Fail.fail("Division by zero") else a / b
|
||||
|
||||
// A function that can fail
|
||||
fn safeDivide(a: Int, b: Int): Int with {Fail} =
|
||||
if b == 0 then Fail.fail("Division by zero")
|
||||
else a / b
|
||||
fn validatePositive(n: Int): Int with {Fail} = if n < 0 then Fail.fail("Negative number not allowed") else n
|
||||
|
||||
// A function that validates input
|
||||
fn validatePositive(n: Int): Int with {Fail} =
|
||||
if n < 0 then Fail.fail("Negative number not allowed")
|
||||
else n
|
||||
|
||||
// A computation that uses multiple effects
|
||||
fn compute(input: Int): Int with {Console, Fail} = {
|
||||
Console.print("Starting computation...")
|
||||
Console.print("Step 1: validating input")
|
||||
@@ -36,7 +12,6 @@ fn compute(input: Int): Int with {Console, Fail} = {
|
||||
result
|
||||
}
|
||||
|
||||
// Main function
|
||||
fn main(): Unit with {Console} = {
|
||||
let result = run compute(21) with {}
|
||||
Console.print("Done!")
|
||||
|
||||
Reference in New Issue
Block a user