2024-04-02 13:11:15 +01:00
|
|
|
local result = require("../lib/result")
|
2024-04-01 07:35:59 +01:00
|
|
|
type Result<T, E> = result.Result<T, E>
|
|
|
|
local Ok = result.Ok
|
|
|
|
local Err = result.Err
|
|
|
|
|
|
|
|
local function canError(): Result<number, string>
|
2024-07-15 14:16:36 +01:00
|
|
|
if math.round(math.random()) == 1 then
|
|
|
|
return Err("you DIED")
|
|
|
|
end
|
2024-04-01 07:35:59 +01:00
|
|
|
|
2024-07-15 14:16:36 +01:00
|
|
|
return Ok(69)
|
2024-04-01 07:35:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function main()
|
2024-07-15 14:16:36 +01:00
|
|
|
local val = canError():unwrap()
|
2024-04-01 07:35:59 +01:00
|
|
|
|
2024-07-15 14:16:36 +01:00
|
|
|
print("got value: ", val)
|
2024-04-01 07:35:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return main()
|