Skip to main content

Option

Lua implementation of Rust's Option Enum

Functions

new

Constructor
Option.new(valueany?) → Option

none

Option.none() → Option

Creates a None Option

some

Option.some(valueany) → Option

Creates a Some Option

wrap

Option.wrap(valueany) → Option

Wraps a value in a Option

isNone

Option:isNone() → boolean

Returns true if Option is a None

isSome

Option:isSome() → boolean

Returns true if Option is a Some

contains

Option:contains(valueany) → boolean

Returns true if value is equal to the contained value

expect

Option:expect(
msgstring,
levelnumber?
) → any

Unwraps and returns the value if is a Some. Otherwise, throws an error with the given message

unwrap

Option:unwrap() → any

Unwraps and returns the value if is a Some. Otherwise, throws an error

unwrapOr

Option:unwrapOr(defaultany) → any

Like unwrap, but returns the given default value instead of erroring

unwrapOrElse

Option:unwrapOrElse(func() → any) → any

Like unwrapOr, but returns the value returned by the given function

map

Option:map(func() → any) → Option

Maps the Option's value to a new one returned by the mapping function then returns a new Option containing it. Returns a None if isNone()

mapOr

Option:mapOr(
defaultany,
func() → any
) → Option

Like map, but if None, returns the default value

mapOrElse

Option:mapOrElse(
default() → any,
func() → any
) → Option

Like map, but if None, returns the value returned by the default function

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option"
                }
            ],
            "function_type": "static",
            "tags": [
                "Constructor"
            ],
            "source": {
                "line": 11,
                "path": "src/shared/modules/Option.lua"
            }
        },
        {
            "name": "none",
            "desc": "Creates a `None` Option",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 21,
                "path": "src/shared/modules/Option.lua"
            }
        },
        {
            "name": "some",
            "desc": "Creates a `Some` Option",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 28,
                "path": "src/shared/modules/Option.lua"
            }
        },
        {
            "name": "wrap",
            "desc": "Wraps a value in a Option",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 35,
                "path": "src/shared/modules/Option.lua"
            }
        },
        {
            "name": "isNone",
            "desc": "Returns true if Option is a `None`",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 41,
                "path": "src/shared/modules/Option.lua"
            }
        },
        {
            "name": "isSome",
            "desc": "Returns true if Option is a `Some`",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 47,
                "path": "src/shared/modules/Option.lua"
            }
        },
        {
            "name": "contains",
            "desc": "Returns true if value is equal to the contained value",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 54,
                "path": "src/shared/modules/Option.lua"
            }
        },
        {
            "name": "expect",
            "desc": "Unwraps and returns the value if is a `Some`.\nOtherwise, throws an error with the given message",
            "params": [
                {
                    "name": "msg",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "level",
                    "desc": "",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 62,
                "path": "src/shared/modules/Option.lua"
            }
        },
        {
            "name": "unwrap",
            "desc": "Unwraps and returns the value if is a `Some`.\nOtherwise, throws an error",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 79,
                "path": "src/shared/modules/Option.lua"
            }
        },
        {
            "name": "unwrapOr",
            "desc": "Like unwrap, but returns the given default value instead of erroring",
            "params": [
                {
                    "name": "default",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 86,
                "path": "src/shared/modules/Option.lua"
            }
        },
        {
            "name": "unwrapOrElse",
            "desc": "Like unwrapOr, but returns the value returned by the given function",
            "params": [
                {
                    "name": "func",
                    "desc": "",
                    "lua_type": "() -> any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 97,
                "path": "src/shared/modules/Option.lua"
            }
        },
        {
            "name": "map",
            "desc": "Maps the Option's value to a new one returned by the mapping function\nthen returns a new Option containing it.\nReturns a `None` if isNone()",
            "params": [
                {
                    "name": "func",
                    "desc": "",
                    "lua_type": "() -> any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 110,
                "path": "src/shared/modules/Option.lua"
            }
        },
        {
            "name": "mapOr",
            "desc": "Like map, but if `None`, returns the default value",
            "params": [
                {
                    "name": "default",
                    "desc": "",
                    "lua_type": "any"
                },
                {
                    "name": "func",
                    "desc": "",
                    "lua_type": "() -> any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 118,
                "path": "src/shared/modules/Option.lua"
            }
        },
        {
            "name": "mapOrElse",
            "desc": "Like map, but if `None`, returns the value returned by the default function",
            "params": [
                {
                    "name": "default",
                    "desc": "",
                    "lua_type": "() -> any"
                },
                {
                    "name": "func",
                    "desc": "",
                    "lua_type": "() -> any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 134,
                "path": "src/shared/modules/Option.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Option",
    "desc": "Lua implementation of Rust's Option Enum",
    "source": {
        "line": 4,
        "path": "src/shared/modules/Option.lua"
    }
}