mirror of
https://github.com/CompeyDev/rusty-luau.git
synced 2024-12-12 12:50:40 +00:00
Erica Marigold
fb97755cad
* Include moonwave doc comments for `Result` * Renamed `Option:getInner` to `Option:unwrapUnchecked` * Updated both `Option.__eq` and `Result.__eq` to support tables * Replaced nil returns in types with unit type * Make unimplemented methods throw an error * Rename `Result.exceptErr` to `Result.expectErr` * Add missing return type in `Result.unwrapOrElse`
38 lines
811 B
Lua
38 lines
811 B
Lua
-- From https://gist.github.com/sapphyrus/fd9aeb871e3ce966cc4b0b969f62f539
|
|
local function tableEq(tbl1, tbl2)
|
|
if tbl1 == tbl2 then
|
|
return true
|
|
elseif type(tbl1) == "table" and type(tbl2) == "table" then
|
|
for key1, value1 in pairs(tbl1) do
|
|
local value2 = tbl2[key1]
|
|
|
|
if value2 == nil then
|
|
-- avoid the type call for missing keys in tbl2 by directly comparing with nil
|
|
return false
|
|
elseif value1 ~= value2 then
|
|
if type(value1) == "table" and type(value2) == "table" then
|
|
if not tableEq(value1, value2) then
|
|
return false
|
|
end
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
end
|
|
|
|
-- check for missing keys in tbl1
|
|
for key2, _ in pairs(tbl2) do
|
|
if tbl1[key2] == nil then
|
|
return false
|
|
end
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
return {
|
|
tableEq = tableEq,
|
|
}
|