Skip to main content

Draft

Helper functions for use with Drafts. These are reexported from Immut.

Properties

None

Draft.None: None

When returned from a recipe, the next value will be nil.

local new = produce(state, function(draft)
	return None
end)

print(new) -- nil

nothing

Draft.nothing: None

Alias for None

Functions

current

Draft.current(draftDraft<State>) → State

Returns a snapshot of the current state of a draft. This can be expensive! Use it sparingly.

original

Draft.original(draftDraft<State>) → State

Get the original table from a draft.

insert

Draft.insert(
t{V},
posnumber,
valueV
) → ()

remove

Draft.remove(
t{V},
posnumber?
) → V?

sort

Draft.sort(
t{V},
compfunction
) → ()

clear

Draft.clear(t{[K]V}) → ()

find

Draft.find(
haystack{[K]V},
needleV,
initnumber
) → number?

concat

Draft.concat(
t{V},
sepstring?,
inumber?,
jnumber?
) → string
Show raw api
{
    "functions": [
        {
            "name": "current",
            "desc": "Returns a snapshot of the current state of a draft. This can be expensive!\nUse it sparingly.",
            "params": [
                {
                    "name": "draft",
                    "desc": "",
                    "lua_type": "Draft<State>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "State"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 19,
                "path": "src/Draft.luau"
            }
        },
        {
            "name": "original",
            "desc": "Get the original table from a draft.",
            "params": [
                {
                    "name": "draft",
                    "desc": "",
                    "lua_type": "Draft<State>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "State"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 28,
                "path": "src/Draft.luau"
            }
        },
        {
            "name": "insert",
            "desc": "Draft-safe replacement for `table.insert`.\n\nhttps://create.roblox.com/docs/reference/engine/libraries/table#insert",
            "params": [
                {
                    "name": "t",
                    "desc": "",
                    "lua_type": "{ V }"
                },
                {
                    "name": "pos",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "V"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 40,
                "path": "src/Draft.luau"
            }
        },
        {
            "name": "remove",
            "desc": "Draft-safe replacement for `table.remove`.\n\nhttps://create.roblox.com/docs/reference/engine/libraries/table#remove",
            "params": [
                {
                    "name": "t",
                    "desc": "",
                    "lua_type": "{ V }"
                },
                {
                    "name": "pos",
                    "desc": "",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "V?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 52,
                "path": "src/Draft.luau"
            }
        },
        {
            "name": "sort",
            "desc": "Draft-safe replacement for `table.sort`.\n\nhttps://create.roblox.com/docs/reference/engine/libraries/table#sort",
            "params": [
                {
                    "name": "t",
                    "desc": "",
                    "lua_type": "{ V }"
                },
                {
                    "name": "comp",
                    "desc": "",
                    "lua_type": "function"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 63,
                "path": "src/Draft.luau"
            }
        },
        {
            "name": "clear",
            "desc": "Draft-safe replacement for `table.clear`.\n\nhttps://create.roblox.com/docs/reference/engine/libraries/table#clear",
            "params": [
                {
                    "name": "t",
                    "desc": "",
                    "lua_type": "{ [K]: V }"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 73,
                "path": "src/Draft.luau"
            }
        },
        {
            "name": "find",
            "desc": "Draft-safe replacement for `table.find`.\n\nhttps://create.roblox.com/docs/reference/engine/libraries/table#find",
            "params": [
                {
                    "name": "haystack",
                    "desc": "",
                    "lua_type": "{ [K]: V }"
                },
                {
                    "name": "needle",
                    "desc": "",
                    "lua_type": "V"
                },
                {
                    "name": "init",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 86,
                "path": "src/Draft.luau"
            }
        },
        {
            "name": "concat",
            "desc": "Draft-safe replacement for `table.find`.\n\nhttps://create.roblox.com/docs/reference/engine/libraries/table#concat",
            "params": [
                {
                    "name": "t",
                    "desc": "",
                    "lua_type": "{ V }"
                },
                {
                    "name": "sep",
                    "desc": "",
                    "lua_type": "string?"
                },
                {
                    "name": "i",
                    "desc": "",
                    "lua_type": "number?"
                },
                {
                    "name": "j",
                    "desc": "",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 100,
                "path": "src/Draft.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "None",
            "desc": "When returned from a recipe, the next value will be nil.\n\n```lua\nlocal new = produce(state, function(draft)\n\treturn None\nend)\n\nprint(new) -- nil\n```",
            "lua_type": "None",
            "source": {
                "line": 115,
                "path": "src/Draft.luau"
            }
        },
        {
            "name": "nothing",
            "desc": "Alias for [`None`](/api/Draft#None)",
            "lua_type": "None",
            "source": {
                "line": 122,
                "path": "src/Draft.luau"
            }
        }
    ],
    "types": [],
    "name": "Draft",
    "desc": "Helper functions for use with Drafts. These are reexported from\n[Immut](https://github.com/solarhorizon/immut).",
    "source": {
        "line": 9,
        "path": "src/Draft.luau"
    }
}