style: auto-format example files with lux fmt
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,21 +1,8 @@
|
||||
// Demonstrating resumable effect handlers in Lux
|
||||
//
|
||||
// Handlers can use `resume(value)` to return a value to the effect call site
|
||||
// and continue the computation. This enables powerful control flow patterns.
|
||||
//
|
||||
// Expected output:
|
||||
// [INFO] Starting computation
|
||||
// [DEBUG] Intermediate result: 10
|
||||
// [INFO] Computation complete
|
||||
// Final result: 20
|
||||
|
||||
// Define a custom logging effect
|
||||
effect Logger {
|
||||
fn log(level: String, msg: String): Unit
|
||||
fn getLogLevel(): String
|
||||
}
|
||||
|
||||
// A function that uses the Logger effect
|
||||
fn compute(): Int with {Logger} = {
|
||||
Logger.log("INFO", "Starting computation")
|
||||
let x = 10
|
||||
@@ -25,20 +12,19 @@ fn compute(): Int with {Logger} = {
|
||||
result
|
||||
}
|
||||
|
||||
// A handler that prints logs with brackets and resumes with Unit
|
||||
handler prettyLogger: Logger {
|
||||
fn log(level, msg) = {
|
||||
Console.print("[" + level + "] " + msg)
|
||||
resume(())
|
||||
}
|
||||
fn log(level, msg) =
|
||||
{
|
||||
Console.print("[" + level + "] " + msg)
|
||||
resume(())
|
||||
}
|
||||
fn getLogLevel() = resume("DEBUG")
|
||||
}
|
||||
|
||||
// Main function
|
||||
fn main(): Unit with {Console} = {
|
||||
let result = run compute() with {
|
||||
Logger = prettyLogger
|
||||
}
|
||||
Logger = prettyLogger,
|
||||
}
|
||||
Console.print("Final result: " + toString(result))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user