Files
lux/examples/effects.lux
2026-02-17 06:52:44 -05:00

26 lines
594 B
Plaintext

effect Logger {
fn log(level: String, msg: String): Unit
fn getLevel(): String
}
fn processData(data: Int): Int with {Logger} = {
Logger.log("info", "Processing data...")
let result = data * 2
Logger.log("debug", "Result computed")
result
}
handler consoleLogger: Logger {
fn log(level, msg) = Console.print("[" + level + "] " + msg)
fn getLevel() = "debug"
}
fn main(): Unit with {Console} = {
let result = run processData(21) with {
Logger = consoleLogger,
}
Console.print("Final result: " + toString(result))
}
let output = run main() with {}