Skip to content

tableext

luau
local tableext = require("@std/tableext")

WARNING

These APIs are still open to future evolution. In new major versions, they may change in backwards incompatible ways.

Summary

EntryDescription
allReturns true if predicate returns true for every element of arr.
anyReturns true if predicate returns true for at least one element of arr.
combineMerges all additional tables into tbl in order. When the same key appears in multiple tables, the value from the last table containing that key wins. Returns tbl.
deepCloneRecursively deep-clones tbl. By default, metatables are stripped, keys are kept as-is without any cloning, and frozenness of tables is not preserved.
extendAppends all elements from each additional array into tbl in order, mutating it in place.
filterReturns a new table containing only the key-value pairs from table for which predicate returns true.
findReturns the first key-value pair from table for which predicate returns true. Returns nil, nil if the predicate does not hold for any value.
keysReturns an array of all keys in tbl. Order is not guaranteed.
mapReturns a new table with the same keys as table, where each value has been transformed by applying f to it.
mapConcatMaps each element of arr through map and joins the resulting strings with sep (default "").
reverseReturns tbl with its elements in reverse order. If inplace is true, reverses tbl in place; otherwise returns a new array.
toSet
valuesReturns an array of all values in tbl. Order is not guaranteed.

Functions and Properties

tableext.all

Returns true if predicate returns true for every element of arr.

luau
(arr: { T }, predicate: (T) -> boolean) -> boolean

tableext.any

Returns true if predicate returns true for at least one element of arr.

luau
(arr: { T }, predicate: (T) -> boolean) -> boolean

tableext.combine

Merges all additional tables into tbl in order. When the same key appears in multiple tables, the value from the last table containing that key wins. Returns tbl.

luau
(tbl: { [K]: V }, ...: { [K]: V }) -> { [K]: V }

tableext.deepClone

Recursively deep-clones tbl. By default, metatables are stripped, keys are kept as-is without any cloning, and frozenness of tables is not preserved.

If options.preserveMetatables is true, metatables are copied onto cloned tables (the metatable itself

is shared, not cloned; tables with protected metatables via __metatable are skipped).

If options.cloneKeys is true, keys that are tables will also be deep-cloned.

If options.preserveFrozen is true, any root level and nested tables that are frozen will be frozen in the clone.

luau
(tbl: T, options: DeepCloneOptions?) -> T

tableext.extend

Appends all elements from each additional array into tbl in order, mutating it in place.

luau
(tbl: { T }, ...: { T }) -> ()

tableext.filter

Returns a new table containing only the key-value pairs from table for which predicate returns true.

luau
(table: { [K]: V }, predicate: (V) -> boolean) -> { [K]: V }

tableext.find

Returns the first key-value pair from table for which predicate returns true. Returns nil, nil if the predicate does not hold for any value.

luau
(table: { [K]: V }, predicate: (V) -> boolean) -> (V?, K?)

tableext.keys

Returns an array of all keys in tbl. Order is not guaranteed.

luau
(tbl: { [K]: V }) -> { K }

tableext.map

Returns a new table with the same keys as table, where each value has been transformed by applying f to it.

luau
(table: { [K]: A }, f: (A) -> B) -> { [K]: B }

tableext.mapConcat

Maps each element of arr through map and joins the resulting strings with sep (default "").

luau
(arr: { T }, map: (T) -> string, sep: string?) -> string

tableext.reverse

Returns tbl with its elements in reverse order. If inplace is true, reverses tbl in place; otherwise returns a new array.

luau
(tbl: { T }, inplace: boolean?) -> { T }

tableext.toSet

luau
(tbl: { T }) -> { [T]: true }

tableext.values

Returns an array of all values in tbl. Order is not guaranteed.

luau
(tbl: { [K]: V }) -> { V }