Add result example as long-term goal.

This commit is contained in:
Jesse Brault 2026-03-04 22:15:07 -06:00
parent 7d8df883e6
commit b4ebee0c34

26
examples/result.dm Normal file
View File

@ -0,0 +1,26 @@
enum Result<T, E>
Ok(T),
Err(E)
end
int Error
message: String
end
class BadArgumentError(argument: String) : Error
pub message = "Invalid argument: ${argument}"
end
fn main(args: Array<String>) -> Result<Int, Error>
let left = args.get(0).flatMap(Int::parse)
if left is None then
return Err(BadArgumentError(args.get(0)))
end
let right = args.get(1).flatMap(Int::parse)
if right is None then
return Err(BadArgumentError(args.get(1)))
end
Ok(left.unwrap() + right.unwrap())
end