Skip to main content

Option

Type Option represents an optional value: every Option is either Option:Some and contains a value, or Option:None, and does not. Common uses of an Option may involve:

  • Initial values
  • Return values for functions that are not defined over their entire input range (partial functions)
  • Return value for otherwise reporting simple errors, where None is returned on error
  • Optional object fields
  • Values that can be loaned or “taken”
  • Optional function arguments
function divide(numerator: number, denominator: number): Option<number>
	if denominator == 0 then
		None()
	else
		return Some(numerator / denominator)
	end
end

Functions

okOr

Option.okOr(
selfOption<T>,
errE
) → Result<T,E>

Transforms the Option<T> into a Result<T, E>, mapping Option:Some(v) to Result:Ok(v) and Option:None to Result:Err(err).

Arguments passed to Option:okOr are eagerly evaluated; if you are passing the result of a function call, it is recommended to use Option:okOrElse, which is lazily evaluated.

local x: Option<string> = Some("foo")
assert(x:okOr(0) == Ok("foo"))

x = None()
assert(x:okOr(0) == Err(0))

okOrElse

Option.okOrElse(
selfOption<T>,
err() → E
) → Result<T,E>

Transforms the Option<T> into a Result<T, E>, mapping Option:Some(v) to Result:Ok(v) and Option:None to Result:Err(err()).

local x: Option<string> = Some("foo")
assert(x:okOrElse(function() return 0 end) == Ok("foo"))

x = None()
assert(x:okOrElse(function() return 0 end) == Err(0))

transpose

Option.transpose(selfOption<Result<T,E>>) → Result<Option<T>,E>

Transposes a Option of an Result into an Result of a Option.

Option:None will be mapped to Result:Ok(Option:None). Option:Some(Result:Ok(_)) and Option:Some(Result:Err(_)) will be mapped to Result:Ok(Option:Some(_)) and Result:Err(_).

type SomeErr = {}

local x: Result<Option<number>, SomeErr> = Ok(Some(5))
local y: Option<Result<number, SomeErr>> = Some(Ok(5))
assert(x == y:transpose())

None

Option.None() → Option<T>

No value.

Some

Option.Some(valT) → Option<T>

Some value of type T.

new

Option.new(
valT?--

The value to convert into an Option

) → Option<T>

Converts a potentially nil value into an Option.

isSome

Option.isSome(selfOption<T>) → boolean

Returns true is the Option is an Option:Some value.

isSomeAnd

Option.isSomeAnd(
selfOption<T>,
op(valT) → boolean--

The predicate function

) → boolean

Returns true is the Option is an Option:Some value and the value inside of it matches a predicate.

isNone

Option.isNone(selfOption<T>) → boolean

Returns true is the Option is an Option:None value.

expect

Option.expect(
selfOption<T>,
msgstring--

The panic message

) → boolean

Returns the Option:Some.

local x: Option<string> = Some("value")
assert(x:expect("fruits are healthy") == "value")
local x: Option<string> = None()
x:expect("fruits are healthy") -- panics with `fruits are healthy`

Errors

TypeDescription
panicPanics if there is an [Option:None] with a custom panic message provided by `msg`.

unwrap

Option.unwrap(selfOption<T>) → T | never

Returns the Option:Some.

Because this function may panic, its use is generally discouraged. Instead, prefer to use Option:unwrapOr, Option:unwrapOrElse, or Option:unwrapOrDefault.

Errors

TypeDescription
panicPanics if the self value is [Option:None].

unwrapOr

Option.unwrapOr(
selfOption<T>,
defaultT--

The default value

) → T

Returns the contained Option:Some value or a provided default.

Arguments passed to unwrap_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use Option:unwrapOrElse, which is lazily evaluated.

assert(Some("car"):unwrapOr("bike") == "car")
assert(None():unwrapOr("bike") == "bike")

unwrapOrElse

Option.unwrapOrElse(
selfOption<T>,
default() → T--

The function which computes the default value

) → T

Returns the contained Option:Some value or computes it from a function.

local k = 10
assert(Some(4).unwrapOrElse(function()
	return 2 * k
end) == 4)
assert(None().unwrapOrElse(function()
	return 2 * k 
end) == 20)

map

Option.map(
selfOption<T>,
op(xT) → U?--

The function to apply

) → Option<U>

Maps an Option to Option by applying a function to a contained value (if Option:Some) or returns Option:None(if Option:None).

local maybeSomeString: Option<string> = Some("Hello, World!")

local maybeSomeLen: Option<number> = maybeSomeString:map(function(s)
	return #s
end)
assert(maybeSomeLen == 13)

local x: Option<string> = None()
assert(x:map(function(s) 
	return #s
end) == None())

inspect

Option.inspect(
selfOption<T>,
op(xT) → ()--

The function to call

) → Option<T>

Calls the provided closure with the contained value (if Option:Some).

local v = { 1, 2, 3, 4, 5 }

-- prints "got: 4"
local x: Option<number> = Option.new(v[4]):inspect(function(x)
	print("got: " .. x)
end)

-- prints nothing
local x: Option<number> = Option.new(v[5]):inspect(function(x) 
	print("got: " .. x)
end)

mapOr

Option.mapOr(
selfOption<T>,
defaultU,--

The default value

op(valT) → U--

The function to apply

) → Option<T>

Returns the provided default result (if none), or applies a function to the contained value (if any).

Arguments passed to Option:mapOr are eagerly evaluated; if you are passing the result of a function call, it is recommended to use Option:mapOrElse, which is lazily evaluated.

local x: Option<string> = Some("foo")
assert(x.mapOr(42, function(v) return #v end) == 3)

local x: Option<string> = None()
assert(x.mapOr(42, function(v) return #v end) == 42)

mapOrElse

Option.mapOrElse(
selfOption<T>,
default() → U,--

The function to compute the default value

op(valT) → U--

The function to apply

) → Option<T>

Computes a default function result (if none), or applies a different function to the contained value (if any).

local k = 21;

local x: Option<string> = Some("foo")
assert(
	x:mapOrElse(
		function() return 2 * k end,
		function(v) return #v end
	) == 3
)

local x: Option<string> = None()
assert(
	x:mapOrElse(
		function() return 2 * k end,
		function(v) return #v end
	) == 42
)

and_

Option.and_(
selfOption<T>,
optbOption<U>--

The other option

) → Option<U>

Returns Option:None if the option is Option:None, otherwise returns optb.

Arguments passed to and are eagerly evaluated; if you are passing the result of a function call, it is recommended to use Option:andThen, which is lazily evaluated.

local x: Option<number> = Some(2)
local y: Option<String> = None()
assert(x:and_(y) == None())

local x: Option<number> = None()
local y: Option<string> = Some("foo")
assert(x:and_(y) == None())

local x: Option<number> = Some(2)
local y: Option<string> = Some("foo")
assert(x:and_(y) == Some("foo"))

local x: Option<u32> = None()
local y: Option<string> = None()
assert(x:and_(y), None())

andThen

Option.andThen(
selfOption<T>,
op(valT) → Option<U>--

The function to call

) → Option<U>

Returns Option:None if the option is Option:None, otherwise calls op with the wrapped value and returns the result.

Some languages call this operation flatmap.

function sqThenToString(x: number): Option<string>
	return Option.new(x ^ 2):map(function(sq)
		return tostring(sq)
	end)
end

assert(Some(2):andThen(sqThenToString) == Some(tostring(4)))
assert(None():andThen(sqThenToString) == None())

Often used to chain fallible operations that may return Option:None.

local arr2d = { { "A0", "A1" }, { "B0", "B1" } }

local item01: Option<string> = Option.new(arr2d[1]):andThen(function(row)
	return row[2]
end)
assert(item01 == Some("A1"))

local item20: Option<string> = Option.new(arr2d[3]):andThen(function(row)
	return row[0]
end)
assert(item20 == None())

filter

Option.filter(
selfOption<T>,
predicate(valT) → boolean--

The predicate function which must match an element

) → Option<T>

Returns Option:None if the option is Option:None, otherwise calls predicate with the wrapped value and returns:

  • Option:Some if predicate returns true (where t is the wrapped value), and
  • Option:None if predicate returns false.
function isEven(n: number): boolean
	return n % 2 == 0
end

assert(None():filter(isEven) == None())
assert(Some(3):filter(isEven) == None())
assert(Some(4):filter(isEven) == Some(4))

or_

Option.or_(
selfOption<T>,
optbOption<T>--

The other option

) → Option<T>

Returns the option if it contains a value, otherwise returns optb.

Arguments passed to Option:or_ are eagerly evaluated; if you are passing the result of a function call, it is recommended to use Option:orElse, which is lazily evaluated.

local x: Option<number> = Some(2)
local y: Option<number> = None()
assert(x:or_(y) == Some(2))

local x: Option<number> = None()
local y: Option<number> = Some(100)
assert(x:or_(y) == Some(100))

local x: Option<number> = Some(2)
local y: Option<number> = Some(100)
assert(x:or_(y) == Some(2))

local x: Option<number> = None()
local y: Option<number> = None()
assert(x:or_(y), None())

orElse

Option.orElse(
selfOption<T>,
op() → Option<T>--

The function to call

) → Option<T>

Returns the option if it contains a value, otherwise calls op and returns the result.

function nobody(): Option<string>
	return None()
end
function vikings(): Option<string>
	return Some("vikings")
end

assert(Some("barbarians"):orElse(vikings) == Some("barbarians"))
assert(None():orElse(vikings) == Some("vikings"))
assert(None():orElse(nobody) == None())

xor

Option.xor(
selfOption<T>,
optbOption<T>--

The other option

) → Option<T>

Returns Option:Some if exactly one of self, optb is Option:Some, otherwise returns Option:None.

local x: Option<number> = Some(2)
local y: Option<number> = None()
assert(x:xor(y) == Some(2))

local x: Option<number> = None()
local y: Option<number> = Some(2)
assert(x:xor(y) == Some(2))

local x: Option<number> = Some(2)
local y: Option<number> = Some(2)
assert(x:xor(y) == None())

local x: Option<number> = None()
local y: Option<number> = None()
assert(x:xor(y) == None())

insert

Option.insert(
selfOption<T>,
valT--

The value to insert

) → T

Inserts value into the option, then returns it.

If the option already contains a value, the old value is dropped.

See also Option:getOrInsert, which doesn’t update the value if the option already contains Option:Some.

local opt: Option<number> = None()
local val: number = opt:insert(1)
assert(val == 1)
assert(opt:unwrap() == 1)

local val: number = opt:insert(2)
assert(val == 2)

getOrInsert

Option.getOrInsert(
selfOption<T>,
valT--

The value to insert

) → T

Inserts value into the option, then returns it.

If the option already contains a value, the old value is dropped.

See also Option:getOrInsert, which doesn’t update the value if the option already contains Option:Some.

local opt: Option<number> = None()
local val: number = opt:insert(1)
assert(val == 1)
assert(opt:unwrap() == 1)

local val: number = opt:insert(2)
assert(val == 2)

take

Option.take(selfOption<T>) → Option<T>

Takes the value out of the option, leaving an Option:None in its place.

local x: Option<number> = Some(2)
local y: Option<number> = x.take()
assert(x == None())
assert(y == Some(2))

local x: Option<number> = None()
local y: Option<number> = x.take()
assert(x == None())
assert(y == None())

replace

Option.replace(
selfOption<T>,
valT
) → Option<T>

Replaces the actual value in the option by the value given in parameter, returning the old value if present, leaving an Option:Some in its place without deinitializing either one.

local x: Option<number> = Some(2)
local old: Option<number> = x:replace(5)
assert(x == Some(5))
assert(old == Some(2))

local x: Option<number> = None()
local old: Option<number> = x:replace(3)
assert(x == Some(3))
assert(old == None())

contains

Option.contains(
selfOption<T>,
valT
) → boolean

Returns true if val is contained in the Option:Some.

local x: Option<number> = Some(2)
local y: Option<number> = None()

assert(x:contains(2))
assert(x:contains(4))
assert(not y:contains(2))

zip

Option.zip(
selfOption<T>,
otherOption>U>
) → Option<{T | U}>

Zips self with another Option.

If self is Option:Some and other is Option:Some, this method returns Option:Some({s, o}). Otherwise, Option:None is returned.

local x: Option<number> = Some(1)
local y: Option<string> = Some("hi")
local z: Option<number> = None()

assert(x:zip(y) == Some({ 1, "hi" }))
assert(x:zip(z) == None())

zipWith

Option.zipWith(
selfOption<T>,
otherOption>U>,
op(
xT,
yU
) → R?
) → Option<R>

Zips self and another Option with function op.

If self is Option:Some and other is Option:Some, this method returns Option:Some(op(s, o)). Otherwise, Option:None is returned.

type Point = {
	x: number,
	y: number,
}
local Point: Point & {
	new: (x: number, y: number) -> Point,
} = {}

function Point.new(x: number, y: number): Point
	return {
		x = x,
		y = y,
	}
end

local xCoord: Option<number> = Some(17.5)
local yCoord: Option<number> = Some(42.7)

assert(xCoord:zipWith(yCoord, Point.new), Some({ x = 17.5, y = 42.7 }))
assert(x:zipWith(None(), Point.new), None())

unzip

Option.unzip(selfOption<T>) → (
Option<A>,
)

Unzips an option containing a table of two options.

If self is Some({a, b}) this method returns (Some(a), Some(b)). Otherwise, (None(), None()) is returned.

local x: Option<{ number | string }> = Some({ 1, "hi" })
local y: Option<{ number }> = None()

assert((x:unzip() == Some(1), Some("hi")))
assert((y:unzip() == None(), None()))

unwrapUnchecked

Option.unwrapUnchecked(selfOption<T>) → T?

Returns the inner value wrapped by the Option.

local x: Option<string> = Some("lol")
local y: Option<string> = None()

assert(x:unwrapUnchecked() == "lol")
assert(y:unwrapUnchecked() == nil)

display

Option.display(selfOption<T>) → string

Returns a formatted representation of the option, often used for printing to stdout.

local x: Option<number> = Some(123)
local y: Option<number> = None()

print(x:display()) -- prints `Option::Some(123)`
print(y:display()) -- prints `Option::None`
Show raw api
{
    "functions": [
        {
            "name": "okOr",
            "desc": "Transforms the [Option]`<T>` into a [Result]`<T, E>`, mapping [Option:Some]`(v)` \nto [Result:Ok]`(v)` and [Option:None] to [Result:Err]`(err)`.\n\nArguments passed to [Option:okOr] are eagerly evaluated; if you are passing the result \nof a function call, it is recommended to use [Option:okOrElse], which is lazily evaluated.\n\n```lua\nlocal x: Option<string> = Some(\"foo\")\nassert(x:okOr(0) == Ok(\"foo\"))\n\nx = None()\nassert(x:okOr(0) == Err(0))\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "err",
                    "desc": "",
                    "lua_type": "E"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Result<T, E>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 133,
                "path": "lib/conversion.luau"
            }
        },
        {
            "name": "okOrElse",
            "desc": "Transforms the [Option]`<T>` into a [Result]`<T, E>`, mapping [Option:Some]`(v)` to\n[Result:Ok]`(v)` and [Option:None] to [Result:Err]`(err())`.\n\n```lua\nlocal x: Option<string> = Some(\"foo\")\nassert(x:okOrElse(function() return 0 end) == Ok(\"foo\"))\n\nx = None()\nassert(x:okOrElse(function() return 0 end) == Err(0))\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "err",
                    "desc": "",
                    "lua_type": "() -> E"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Result<T, E>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 159,
                "path": "lib/conversion.luau"
            }
        },
        {
            "name": "transpose",
            "desc": "Transposes a [Option] of an [Result] into an [Result] of a [Option].\n\n[Option:None] will be mapped to [Result:Ok]\\([Option:None]\\). \n[Option:Some]\\([Result:Ok]`(_)`\\) and [Option:Some]\\([Result:Err]\\(`_`\\)\\) will \nbe mapped to [Result:Ok]\\([Option:Some]`(_)`\\) and [Result:Err]`(_)`.\n\n```lua\ntype SomeErr = {}\n\nlocal x: Result<Option<number>, SomeErr> = Ok(Some(5))\nlocal y: Option<Result<number, SomeErr>> = Some(Ok(5))\nassert(x == y:transpose())\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<Result<T, E>>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Result<Option<T>, E>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 187,
                "path": "lib/conversion.luau"
            }
        },
        {
            "name": "None",
            "desc": "No value.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<T>\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 39,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "Some",
            "desc": "Some value of type `T`.",
            "params": [
                {
                    "name": "val",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<T>\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 48,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "new",
            "desc": "Converts a potentially `nil` value into an [Option].",
            "params": [
                {
                    "name": "val",
                    "desc": "The value to convert into an [Option]",
                    "lua_type": "T?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 60,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "isSome",
            "desc": "Returns `true` is the [Option] is an [Option:Some] value.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 111,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "isSomeAnd",
            "desc": "Returns `true` is the [Option] is an [Option:Some] value and the value inside of it \nmatches a predicate.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "op",
                    "desc": "The predicate function",
                    "lua_type": "(val: T) -> boolean"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 125,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "isNone",
            "desc": "Returns `true` is the [Option] is an [Option:None] value.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 138,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "expect",
            "desc": "Returns the [Option:Some].\n\n\n```lua\nlocal x: Option<string> = Some(\"value\")\nassert(x:expect(\"fruits are healthy\") == \"value\")\n```\n\n```lua\nlocal x: Option<string> = None()\nx:expect(\"fruits are healthy\") -- panics with `fruits are healthy`\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "msg",
                    "desc": "The panic message",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "errors": [
                {
                    "lua_type": "panic",
                    "desc": "Panics if there is an [Option:None] with a custom panic message provided by `msg`."
                }
            ],
            "source": {
                "line": 163,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "unwrap",
            "desc": "Returns the [Option:Some].\n\nBecause this function may panic, its use is generally discouraged. Instead, prefer to use \n[Option:unwrapOr], [Option:unwrapOrElse], or [Option:unwrapOrDefault].",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T | never"
                }
            ],
            "function_type": "static",
            "errors": [
                {
                    "lua_type": "panic",
                    "desc": "Panics if the self value is [Option:None]."
                }
            ],
            "source": {
                "line": 183,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "unwrapOr",
            "desc": "Returns the contained [Option:Some] value or a provided default.\n\nArguments passed to unwrap_or are eagerly evaluated; if you are passing the result of \na function call, it is recommended to use [Option:unwrapOrElse], which is lazily \nevaluated.\n\n```lua\nassert(Some(\"car\"):unwrapOr(\"bike\") == \"car\")\nassert(None():unwrapOr(\"bike\") == \"bike\")\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "default",
                    "desc": "The default value",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 209,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "unwrapOrElse",
            "desc": "Returns the contained [Option:Some] value or computes it from a function.\n\n```lua\nlocal k = 10\nassert(Some(4).unwrapOrElse(function()\n\treturn 2 * k\nend) == 4)\nassert(None().unwrapOrElse(function()\n\treturn 2 * k \nend) == 20)\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "default",
                    "desc": "The function which computes the default value",
                    "lua_type": "() -> T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 236,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "map",
            "desc": "Maps an [Option]<T> to [Option]<U> by applying a function to a contained value \n(if [Option:Some]) or returns [Option:None](if [Option:None]).\n\n```lua\nlocal maybeSomeString: Option<string> = Some(\"Hello, World!\")\n\nlocal maybeSomeLen: Option<number> = maybeSomeString:map(function(s)\n\treturn #s\nend)\nassert(maybeSomeLen == 13)\n\nlocal x: Option<string> = None()\nassert(x:map(function(s) \n\treturn #s\nend) == None())\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "op",
                    "desc": "The function to apply",
                    "lua_type": "(x: T) -> U?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<U>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 268,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "inspect",
            "desc": "Calls the provided closure with the contained value (if [Option:Some]).\n\n```lua\nlocal v = { 1, 2, 3, 4, 5 }\n\n-- prints \"got: 4\"\nlocal x: Option<number> = Option.new(v[4]):inspect(function(x)\n\tprint(\"got: \" .. x)\nend)\n\n-- prints nothing\nlocal x: Option<number> = Option.new(v[5]):inspect(function(x) \n\tprint(\"got: \" .. x)\nend)\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "op",
                    "desc": "The function to call",
                    "lua_type": "(x: T) -> ()"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 305,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "mapOr",
            "desc": "Returns the provided default result (if none), or applies a function to \nthe contained value (if any).\n\nArguments passed to [Option:mapOr] are eagerly evaluated; if you are passing the \nresult of a function call, it is recommended to use [Option:mapOrElse], \nwhich is lazily evaluated.\n\n```lua\nlocal x: Option<string> = Some(\"foo\")\nassert(x.mapOr(42, function(v) return #v end) == 3)\n\nlocal x: Option<string> = None()\nassert(x.mapOr(42, function(v) return #v end) == 42)\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "default",
                    "desc": "The default value",
                    "lua_type": "U"
                },
                {
                    "name": "op",
                    "desc": "The function to apply",
                    "lua_type": "(val: T) -> U"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 335,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "mapOrElse",
            "desc": "Computes a default function result (if none), or applies a different function \nto the contained value (if any).\n\n```lua\nlocal k = 21;\n\nlocal x: Option<string> = Some(\"foo\")\nassert(\n\tx:mapOrElse(\n\t\tfunction() return 2 * k end,\n\t\tfunction(v) return #v end\n\t) == 3\n)\n\nlocal x: Option<string> = None()\nassert(\n\tx:mapOrElse(\n\t\tfunction() return 2 * k end,\n\t\tfunction(v) return #v end\n\t) == 42\n)\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "default",
                    "desc": "The function to compute the default value",
                    "lua_type": "() -> U"
                },
                {
                    "name": "op",
                    "desc": "The function to apply",
                    "lua_type": "(val: T) -> U"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 374,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "and_",
            "desc": "Returns [Option:None] if the option is [Option:None], otherwise returns `optb`.\n\nArguments passed to and are eagerly evaluated; if you are passing the result of a \nfunction call, it is recommended to use [Option:andThen], which is lazily evaluated.\n\n```lua\nlocal x: Option<number> = Some(2)\nlocal y: Option<String> = None()\nassert(x:and_(y) == None())\n\nlocal x: Option<number> = None()\nlocal y: Option<string> = Some(\"foo\")\nassert(x:and_(y) == None())\n\nlocal x: Option<number> = Some(2)\nlocal y: Option<string> = Some(\"foo\")\nassert(x:and_(y) == Some(\"foo\"))\n\nlocal x: Option<u32> = None()\nlocal y: Option<string> = None()\nassert(x:and_(y), None())\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "optb",
                    "desc": "The other option",
                    "lua_type": "Option<U>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<U>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 417,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "andThen",
            "desc": "Returns [Option:None] if the option is [Option:None], otherwise calls `op` with the wrapped \nvalue and returns the result.\n\nSome languages call this operation flatmap.\n\n```lua\nfunction sqThenToString(x: number): Option<string>\n\treturn Option.new(x ^ 2):map(function(sq)\n\t\treturn tostring(sq)\n\tend)\nend\n\nassert(Some(2):andThen(sqThenToString) == Some(tostring(4)))\nassert(None():andThen(sqThenToString) == None())\n```\n\nOften used to chain fallible operations that may return [Option:None].\n\n```lua\nlocal arr2d = { { \"A0\", \"A1\" }, { \"B0\", \"B1\" } }\n\nlocal item01: Option<string> = Option.new(arr2d[1]):andThen(function(row)\n\treturn row[2]\nend)\nassert(item01 == Some(\"A1\"))\n\nlocal item20: Option<string> = Option.new(arr2d[3]):andThen(function(row)\n\treturn row[0]\nend)\nassert(item20 == None())\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "op",
                    "desc": "The function to call",
                    "lua_type": "(val: T) -> Option<U>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<U>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 464,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "filter",
            "desc": "Returns [Option:None] if the option is [Option:None], otherwise calls `predicate` with \nthe wrapped value and returns:\n\n* [Option:Some](t) if predicate returns `true` (where `t` is the wrapped value), and\n* [Option:None] if predicate returns `false`.\n\n```lua\nfunction isEven(n: number): boolean\n\treturn n % 2 == 0\nend\n\nassert(None():filter(isEven) == None())\nassert(Some(3):filter(isEven) == None())\nassert(Some(4):filter(isEven) == Some(4))\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "predicate",
                    "desc": "The predicate function which must match an element",
                    "lua_type": "(val: T) -> boolean"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 495,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "or_",
            "desc": "Returns the option if it contains a value, otherwise returns `optb`.\n\nArguments passed to [Option:or_] are eagerly evaluated; if you are passing the result of \na function call, it is recommended to use [Option:orElse], which is lazily \nevaluated.\n\n```lua\nlocal x: Option<number> = Some(2)\nlocal y: Option<number> = None()\nassert(x:or_(y) == Some(2))\n\nlocal x: Option<number> = None()\nlocal y: Option<number> = Some(100)\nassert(x:or_(y) == Some(100))\n\nlocal x: Option<number> = Some(2)\nlocal y: Option<number> = Some(100)\nassert(x:or_(y) == Some(2))\n\nlocal x: Option<number> = None()\nlocal y: Option<number> = None()\nassert(x:or_(y), None())\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "optb",
                    "desc": "The other option",
                    "lua_type": "Option<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 536,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "orElse",
            "desc": "Returns the option if it contains a value, otherwise calls `op` and returns the result.\n\n```lua\nfunction nobody(): Option<string>\n\treturn None()\nend\nfunction vikings(): Option<string>\n\treturn Some(\"vikings\")\nend\n\nassert(Some(\"barbarians\"):orElse(vikings) == Some(\"barbarians\"))\nassert(None():orElse(vikings) == Some(\"vikings\"))\nassert(None():orElse(nobody) == None())\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "op",
                    "desc": "The function to call",
                    "lua_type": "() -> Option<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 566,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "xor",
            "desc": "Returns [Option:Some] if exactly one of `self`, `optb` is [Option:Some], \notherwise returns [Option:None].\n\n```lua\nlocal x: Option<number> = Some(2)\nlocal y: Option<number> = None()\nassert(x:xor(y) == Some(2))\n\nlocal x: Option<number> = None()\nlocal y: Option<number> = Some(2)\nassert(x:xor(y) == Some(2))\n\nlocal x: Option<number> = Some(2)\nlocal y: Option<number> = Some(2)\nassert(x:xor(y) == None())\n\nlocal x: Option<number> = None()\nlocal y: Option<number> = None()\nassert(x:xor(y) == None())\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "optb",
                    "desc": "The other option",
                    "lua_type": "Option<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 602,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "insert",
            "desc": "Inserts value into the option, then returns it.\n\nIf the option already contains a value, the old value is dropped.\n\nSee also [Option:getOrInsert], which doesn’t update the value if the \noption already contains [Option:Some].\n\n```lua\nlocal opt: Option<number> = None()\nlocal val: number = opt:insert(1)\nassert(val == 1)\nassert(opt:unwrap() == 1)\n\nlocal val: number = opt:insert(2)\nassert(val == 2)\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "val",
                    "desc": "The value to insert",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 640,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "getOrInsert",
            "desc": "Inserts value into the option, then returns it.\n\nIf the option already contains a value, the old value is dropped.\n\nSee also [Option:getOrInsert], which doesn’t update the value if the \noption already contains [Option:Some].\n\n```lua\nlocal opt: Option<number> = None()\nlocal val: number = opt:insert(1)\nassert(val == 1)\nassert(opt:unwrap() == 1)\n\nlocal val: number = opt:insert(2)\nassert(val == 2)\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "val",
                    "desc": "The value to insert",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 669,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "take",
            "desc": "Takes the value out of the option, leaving an [Option:None] in its place.\n\n```lua\nlocal x: Option<number> = Some(2)\nlocal y: Option<number> = x.take()\nassert(x == None())\nassert(y == Some(2))\n\nlocal x: Option<number> = None()\nlocal y: Option<number> = x.take()\nassert(x == None())\nassert(y == None())\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 697,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "replace",
            "desc": "Replaces the actual value in the option by the value given in parameter, returning \nthe old value if present, leaving an [Option:Some] in its place without \ndeinitializing either one.\n\n```lua\nlocal x: Option<number> = Some(2)\nlocal old: Option<number> = x:replace(5)\nassert(x == Some(5))\nassert(old == Some(2))\n\nlocal x: Option<number> = None()\nlocal old: Option<number> = x:replace(3)\nassert(x == Some(3))\nassert(old == None())\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "val",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 730,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "contains",
            "desc": "Returns true if `val` is contained in the [Option:Some].\n\n```lua\nlocal x: Option<number> = Some(2)\nlocal y: Option<number> = None()\n\nassert(x:contains(2))\nassert(x:contains(4))\nassert(not y:contains(2))\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "val",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 759,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "zip",
            "desc": "Zips `self` with another [Option].\n\nIf `self` is [Option:Some](s) and other is [Option:Some](o), this method returns \n[Option:Some]({s, o}). Otherwise, [Option:None] is returned.\n\n```lua\nlocal x: Option<number> = Some(1)\nlocal y: Option<string> = Some(\"hi\")\nlocal z: Option<number> = None()\n\nassert(x:zip(y) == Some({ 1, \"hi\" }))\nassert(x:zip(z) == None())\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "other",
                    "desc": "",
                    "lua_type": "Option>U>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<{T | U}>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 788,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "zipWith",
            "desc": "Zips `self` and another [Option] with function `op`.\n\nIf `self` is [Option:Some](s) and other is [Option:Some](o), this method returns \n[Option:Some](op(s, o)). Otherwise, [Option:None] is returned.\n\n```lua\ntype Point = {\n\tx: number,\n\ty: number,\n}\nlocal Point: Point & {\n\tnew: (x: number, y: number) -> Point,\n} = {}\n\nfunction Point.new(x: number, y: number): Point\n\treturn {\n\t\tx = x,\n\t\ty = y,\n\t}\nend\n\nlocal xCoord: Option<number> = Some(17.5)\nlocal yCoord: Option<number> = Some(42.7)\n\nassert(xCoord:zipWith(yCoord, Point.new), Some({ x = 17.5, y = 42.7 }))\nassert(x:zipWith(None(), Point.new), None())\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                },
                {
                    "name": "other",
                    "desc": "",
                    "lua_type": "Option>U>"
                },
                {
                    "name": "op",
                    "desc": "",
                    "lua_type": "(x: T, y: U) -> R?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Option<R>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 832,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "unzip",
            "desc": "Unzips an option containing a table of two options.\n\nIf `self` is `Some({a, b})` this method returns `(Some(a), Some(b))`.\nOtherwise, `(None(), None())` is returned.\n\n```lua\nlocal x: Option<{ number | string }> = Some({ 1, \"hi\" })\nlocal y: Option<{ number }> = None()\n\nassert((x:unzip() == Some(1), Some(\"hi\")))\nassert((y:unzip() == None(), None()))\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "(Option<A>, Option<B>)"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 863,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "unwrapUnchecked",
            "desc": "Returns the inner value wrapped by the [Option].\n\n```lua\nlocal x: Option<string> = Some(\"lol\")\nlocal y: Option<string> = None()\n\nassert(x:unwrapUnchecked() == \"lol\")\nassert(y:unwrapUnchecked() == nil)\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 889,
                "path": "lib/option.luau"
            }
        },
        {
            "name": "display",
            "desc": "Returns a formatted representation of the option, often\nused for printing to stdout.\n\n```lua\nlocal x: Option<number> = Some(123)\nlocal y: Option<number> = None()\n\nprint(x:display()) -- prints `Option::Some(123)`\nprint(y:display()) -- prints `Option::None`\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Option<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 910,
                "path": "lib/option.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Option",
    "desc": "Type [Option] represents an optional value: every [Option] is either [Option:Some] \nand contains a value, or [Option:None], and does not. Common uses of an [Option]\nmay involve:\n\n* Initial values\n* Return values for functions that are not defined over their entire input range (partial functions)\n* Return value for otherwise reporting simple errors, where None is returned on error\n* Optional object fields\n* Values that can be loaned or “taken”\n* Optional function arguments\n\n```lua\nfunction divide(numerator: number, denominator: number): Option<number>\n\tif denominator == 0 then\n\t\tNone()\n\telse\n\t\treturn Some(numerator / denominator)\n\tend\nend\n```",
    "source": {
        "line": 27,
        "path": "lib/option.luau"
    }
}