style: auto-format example files with lux fmt

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-17 06:52:44 -05:00
parent 8c90d5a8dc
commit 44ea1eebb0
54 changed files with 580 additions and 1483 deletions

View File

@@ -1,54 +1,43 @@
// Demonstrating generic type parameters in Lux
//
// Expected output:
// identity(42) = 42
// identity("hello") = hello
// first(MkPair(1, "one")) = 1
// second(MkPair(1, "one")) = one
// map(Some(21), double) = Some(42)
// Generic identity function
fn identity<T>(x: T): T = x
// Generic pair type
type Pair<A, B> =
| MkPair(A, B)
fn first<A, B>(p: Pair<A, B>): A =
match p {
MkPair(a, _) => a
}
MkPair(a, _) => a,
}
fn second<A, B>(p: Pair<A, B>): B =
match p {
MkPair(_, b) => b
}
MkPair(_, b) => b,
}
// Generic map function for Option
fn mapOption<T, U>(opt: Option<T>, f: fn(T): U): Option<U> =
match opt {
None => None,
Some(x) => Some(f(x))
}
None => None,
Some(x) => Some(f(x)),
}
// Helper function for testing
fn double(x: Int): Int = x * 2
// Test usage
let id_int = identity(42)
let id_str = identity("hello")
let pair = MkPair(1, "one")
let fst = first(pair)
let snd = second(pair)
let doubled = mapOption(Some(21), double)
fn showOption(opt: Option<Int>): String =
match opt {
None => "None",
Some(x) => "Some(" + toString(x) + ")"
}
None => "None",
Some(x) => "Some(" + toString(x) + ")",
}
fn printResults(): Unit with {Console} = {
Console.print("identity(42) = " + toString(id_int))