Result
Hello developers,
Today I will give you an extremely simple library for error handling
Easy | Result | Simple
Get in on Creator Store | GitHub
Api Usage:
--!strict
local Result = require(path.to.Result)
type Result<T, E> = Result.Result<T, E> -- for more "clean" code
local function some_func(num: number): Result<number, string>
if num == 4 then
return Result.Err("Number is 4!!!")
else
return Result.Ok(num)
end
end
-- functions unwrap, unwrap_err, unwrap_or
local err_result = some_func(4)
--print(Result.unwrap(err_result)) -- <- error, try unwrap on Err
print(Result.unwrap_err(err_result)) -- log: Number if 4!!!
print(Result.is_ok(err_result)) -- log: false
local ok_result = some_func(1337)
print(Result.unwrap(ok_result)) -- log: 1337
print(Result.is_err(ok_result)) -- log: false
print(Result.is_ok(ok_result)) -- log: true
-- example with unwrap_or
local error_result = some_func(4)
print(Result.unwrap_or(error_result, 1)) -- log: 1
This library is very simple, but provides good error handling for any project
- this library sounds good, but idk how rate this
- maybe next time
- i will dont use this(but why
) reply and say why - i will use this right now!
- ill check this library and rate later