Show raw api
{
"functions": [
{
"name": "Some",
"desc": "Creates an Option instance with the given value. Throws an error\nif the given value is `nil`.",
"params": [
{
"name": "value",
"desc": "",
"lua_type": "T"
}
],
"returns": [
{
"desc": "",
"lua_type": "Option<T>"
}
],
"function_type": "static",
"source": {
"line": 145,
"path": "modules/option/init.luau"
}
},
{
"name": "Wrap",
"desc": "Safely wraps the given value as an option. If the\nvalue is `nil`, returns `Option.None`, otherwise\nreturns `Option.Some(value)`.",
"params": [
{
"name": "value",
"desc": "",
"lua_type": "T"
}
],
"returns": [
{
"desc": "",
"lua_type": "Option<T> | Option<None>"
}
],
"function_type": "static",
"source": {
"line": 158,
"path": "modules/option/init.luau"
}
},
{
"name": "Is",
"desc": "Returns `true` if `obj` is an Option.",
"params": [
{
"name": "obj",
"desc": "",
"lua_type": "any"
}
],
"returns": [
{
"desc": "",
"lua_type": "boolean"
}
],
"function_type": "static",
"source": {
"line": 171,
"path": "modules/option/init.luau"
}
},
{
"name": "Assert",
"desc": "Throws an error if `obj` is not an Option.",
"params": [
{
"name": "obj",
"desc": "",
"lua_type": "any"
}
],
"returns": [],
"function_type": "static",
"source": {
"line": 179,
"path": "modules/option/init.luau"
}
},
{
"name": "Deserialize",
"desc": "Deserializes the data into an Option. This data should have come from\nthe `option:Serialize()` method.",
"params": [
{
"name": "data",
"desc": "",
"lua_type": "table"
}
],
"returns": [
{
"desc": "",
"lua_type": "Option"
}
],
"function_type": "static",
"source": {
"line": 189,
"path": "modules/option/init.luau"
}
},
{
"name": "Serialize",
"desc": "Returns a serialized version of the option.",
"params": [],
"returns": [
{
"desc": "",
"lua_type": "table"
}
],
"function_type": "method",
"source": {
"line": 198,
"path": "modules/option/init.luau"
}
},
{
"name": "Match",
"desc": "Matches against the option.\n\n```lua\nlocal opt = Option.Some(32)\nopt:Match {\n\tSome = function(num) print(\"Number\", num) end,\n\tNone = function() print(\"No value\") end,\n}\n```",
"params": [
{
"name": "matches",
"desc": "",
"lua_type": "{Some: (value: any) -> any, None: () -> any}"
}
],
"returns": [
{
"desc": "",
"lua_type": "any"
}
],
"function_type": "method",
"source": {
"line": 219,
"path": "modules/option/init.luau"
}
},
{
"name": "IsSome",
"desc": "Returns `true` if the option has a value.",
"params": [],
"returns": [
{
"desc": "",
"lua_type": "boolean"
}
],
"function_type": "method",
"source": {
"line": 235,
"path": "modules/option/init.luau"
}
},
{
"name": "IsNone",
"desc": "Returns `true` if the option is None.",
"params": [],
"returns": [
{
"desc": "",
"lua_type": "boolean"
}
],
"function_type": "method",
"source": {
"line": 243,
"path": "modules/option/init.luau"
}
},
{
"name": "Expect",
"desc": "Unwraps the value in the option, otherwise throws an error with `msg` as the error message.\n```lua\nlocal opt = Option.Some(10)\nprint(opt:Expect(\"No number\")) -> 10\nprint(Option.None:Expect(\"No number\")) -- Throws an error \"No number\"\n```",
"params": [
{
"name": "msg",
"desc": "",
"lua_type": "string"
}
],
"returns": [
{
"desc": "",
"lua_type": "value: any"
}
],
"function_type": "method",
"source": {
"line": 257,
"path": "modules/option/init.luau"
}
},
{
"name": "ExpectNone",
"desc": "Throws an error with `msg` as the error message if the value is _not_ None.",
"params": [
{
"name": "msg",
"desc": "",
"lua_type": "string"
}
],
"returns": [],
"function_type": "method",
"source": {
"line": 266,
"path": "modules/option/init.luau"
}
},
{
"name": "Unwrap",
"desc": "Returns the value in the option, or throws an error if the option is None.",
"params": [],
"returns": [
{
"desc": "",
"lua_type": "value: any"
}
],
"function_type": "method",
"source": {
"line": 274,
"path": "modules/option/init.luau"
}
},
{
"name": "UnwrapOr",
"desc": "If the option holds a value, returns the value. Otherwise, returns `default`.",
"params": [
{
"name": "default",
"desc": "",
"lua_type": "any"
}
],
"returns": [
{
"desc": "",
"lua_type": "value: any"
}
],
"function_type": "method",
"source": {
"line": 283,
"path": "modules/option/init.luau"
}
},
{
"name": "UnwrapOrElse",
"desc": "If the option holds a value, returns the value. Otherwise, returns the\nresult of the `defaultFn` function.",
"params": [
{
"name": "defaultFn",
"desc": "",
"lua_type": "() -> any"
}
],
"returns": [
{
"desc": "",
"lua_type": "value: any"
}
],
"function_type": "method",
"source": {
"line": 297,
"path": "modules/option/init.luau"
}
},
{
"name": "And",
"desc": "Returns `optionB` if the calling option has a value,\notherwise returns None.\n\n```lua\nlocal optionA = Option.Some(32)\nlocal optionB = Option.Some(64)\nlocal opt = optionA:And(optionB)\n-- opt == optionB\n\nlocal optionA = Option.None\nlocal optionB = Option.Some(64)\nlocal opt = optionA:And(optionB)\n-- opt == Option.None\n```",
"params": [
{
"name": "optionB",
"desc": "",
"lua_type": "Option"
}
],
"returns": [
{
"desc": "",
"lua_type": "Option"
}
],
"function_type": "method",
"source": {
"line": 323,
"path": "modules/option/init.luau"
}
},
{
"name": "AndThen",
"desc": "If the option holds a value, then the `andThenFn`\nfunction is called with the held value of the option,\nand then the resultant Option returned by the `andThenFn`\nis returned. Otherwise, None is returned.\n\n```lua\nlocal optA = Option.Some(32)\nlocal optB = optA:AndThen(function(num)\n\treturn Option.Some(num * 2)\nend)\nprint(optB:Expect(\"Expected number\")) --> 64\n```",
"params": [
{
"name": "andThenFn",
"desc": "",
"lua_type": "(value: any) -> Option"
}
],
"returns": [
{
"desc": "",
"lua_type": "value: Option"
}
],
"function_type": "method",
"source": {
"line": 347,
"path": "modules/option/init.luau"
}
},
{
"name": "Or",
"desc": "If caller has a value, returns itself. Otherwise, returns `optionB`.",
"params": [
{
"name": "optionB",
"desc": "",
"lua_type": "Option"
}
],
"returns": [
{
"desc": "",
"lua_type": "Option"
}
],
"function_type": "method",
"source": {
"line": 362,
"path": "modules/option/init.luau"
}
},
{
"name": "OrElse",
"desc": "If caller has a value, returns itself. Otherwise, returns the\noption generated by the `orElseFn` function.",
"params": [
{
"name": "orElseFn",
"desc": "",
"lua_type": "() -> Option"
}
],
"returns": [
{
"desc": "",
"lua_type": "Option"
}
],
"function_type": "method",
"source": {
"line": 376,
"path": "modules/option/init.luau"
}
},
{
"name": "XOr",
"desc": "If both `self` and `optionB` have values _or_ both don't have a value,\nthen this returns None. Otherwise, it returns the option that does have\na value.",
"params": [
{
"name": "optionB",
"desc": "",
"lua_type": "Option"
}
],
"returns": [
{
"desc": "",
"lua_type": "Option"
}
],
"function_type": "method",
"source": {
"line": 393,
"path": "modules/option/init.luau"
}
},
{
"name": "Filter",
"desc": "Returns `self` if this option has a value and the predicate returns `true.\nOtherwise, returns None.",
"params": [
{
"name": "predicate",
"desc": "",
"lua_type": "(value: any) -> boolean"
}
],
"returns": [
{
"desc": "",
"lua_type": "Option"
}
],
"function_type": "method",
"source": {
"line": 411,
"path": "modules/option/init.luau"
}
},
{
"name": "Contains",
"desc": "Returns `true` if this option contains `value`.",
"params": [
{
"name": "value",
"desc": "",
"lua_type": "any"
}
],
"returns": [
{
"desc": "",
"lua_type": "boolean"
}
],
"function_type": "method",
"source": {
"line": 424,
"path": "modules/option/init.luau"
}
},
{
"name": "__tostring",
"desc": "Metamethod to transform the option into a string.\n```lua\nlocal optA = Option.Some(64)\nlocal optB = Option.None\nprint(optA) --> Option<number>\nprint(optB) --> Option<None>\n```",
"params": [],
"returns": [
{
"desc": "",
"lua_type": "string"
}
],
"function_type": "method",
"source": {
"line": 438,
"path": "modules/option/init.luau"
}
},
{
"name": "__eq",
"desc": "Metamethod to check equality between two options. Returns `true` if both\noptions hold the same value _or_ both options are None.\n```lua\nlocal o1 = Option.Some(32)\nlocal o2 = Option.Some(32)\nlocal o3 = Option.Some(64)\nlocal o4 = Option.None\nlocal o5 = Option.None\n\nprint(o1 == o2) --> true\nprint(o1 == o3) --> false\nprint(o1 == o4) --> false\nprint(o4 == o5) --> true\n```",
"params": [
{
"name": "opt",
"desc": "",
"lua_type": "Option"
}
],
"returns": [
{
"desc": "",
"lua_type": "boolean"
}
],
"function_type": "method",
"source": {
"line": 464,
"path": "modules/option/init.luau"
}
}
],
"properties": [
{
"name": "None",
"desc": "Represents no value.",
"lua_type": "Option<None>",
"source": {
"line": 480,
"path": "modules/option/init.luau"
}
}
],
"types": [],
"name": "Option",
"desc": "Represents an optional value in Lua. This is useful to avoid `nil` bugs, which can\ngo silently undetected within code and cause hidden or hard-to-find bugs.",
"source": {
"line": 126,
"path": "modules/option/init.luau"
}
}