mirror of
https://github.com/CompeyDev/rusty-luau.git
synced 2024-12-12 12:50:40 +00:00
34 lines
No EOL
676 B
Text
34 lines
No EOL
676 B
Text
local Option = {}
|
|
export type Option<T> = typeof(Option) & {
|
|
_optValue: T?,
|
|
typeId: "Option"
|
|
}
|
|
|
|
function None<T>(): Option<T>
|
|
return Option.new(nil) :: Option<T>
|
|
end
|
|
|
|
function Some<T>(val: T): Option<T>
|
|
return Option.new(val) :: Option<T>
|
|
end
|
|
|
|
function Option.new<T>(val: T?)
|
|
return setmetatable({
|
|
_optValue = val,
|
|
typeId = "Option"
|
|
} :: Option<T>, {
|
|
__index = Option,
|
|
__tostring = function(self)
|
|
-- Return formatted enum variants too
|
|
|
|
return `{self.typeId}<T>`
|
|
end
|
|
})
|
|
end
|
|
|
|
return {
|
|
-- TODO: Implement Option utility methods
|
|
Option = Option,
|
|
Some = Some,
|
|
None = None
|
|
} |