local Option = {} export type Option = typeof(Option) & { _optValue: T?, typeId: "Option", } function None(): Option return Option.new(nil) :: Option end function Some(val: T): Option return Option.new(val) :: Option end function Option.new(val: T?) return setmetatable( { _optValue = val, typeId = "Option", } :: Option, { __index = Option, __tostring = function(self: Option) -- TODO: Return formatted enum variants too if self._optValue == nil then return `{self.typeId}::None` else return `{self.typeId}::Some({self._optValue})` end end, } ) end return { -- TODO: Implement Option utility methods Option = Option, Some = Some, None = None, }