ExtraTable

Plenty of useful utilities and common functions for interacting with tables.

Summary

Type
Function

Function

table ShallowCopy(table original)

Function

table DeepCopy(table original)

Function

any Pick(array array, RNG? rng)

Function

boolean IsArray(any table)

Function

boolean IsDictionary(any table)

Function

boolean HasValue(table table, any value)

Function

boolean HasKey(table table, any key)

Function

table Length(table table)

Function

boolean IsEmpty(table table)

Function

table Set(array array)

Function

any? Find(table table, any value)

Function

void PrettyPrint(table master, int depthLimit)

Methods

ShallowCopy()

table ShallowCopy(table original)

Returns a replica of table where nested tables are empty. Useful for when you want to edit the values of an array without changing the original.

DeepCopy()

table DeepCopy(table original)

Returns a replica of table where any nested tables are also recursively copied.

Pick()

any Pick(array array, RNG? rng)

Returns a random value from an array. If rng is omitted, an RNG object with a seed equivalent to the game's current frame count and a shift index of 35 will be created.

IsArray()

boolean IsArray(any value)

Returns true if the provided value is an array or if it is an empty table.

IsDictionary()

boolean IsDictionary(any value)

Returns true if the provided value is a dictionary.

HasValue()

boolean HasValue(table table, any value)

Returns true if the value exists as a value within table.

HasKey()

boolean HasKey(table table, any key)

Returns true if key exists as a key within table.

Length()

int Length(table table)

Returns the amount of entries in table. Works for dictionaries and arrays.

IsEmpty()

boolean IsEmpty(table table)

Returns true if the amount of entries in table is 0.

Set()

dictionary Set(array array)

Returns a new dictionary where there is a key for each entry in array and all values set to true.

Example
local ExtraTable = IsaacHelper.GetModule("ExtraTable")
local test = {"Earth", "Mars", "Jupiter", "Pluto"}

local set = ExtraTable.Set(test)
print(set.Earth) -- true
print(set.Jupiter) -- true 

Find()

any? Find(table table, any value)

Returns the index in which value appears in table, or nil if not found.

PrettyPrint()

void PrettyPrint(table master, int? depthLimit)

Recursively prints the key-value pairs of master. If the method goes depthLimit nested tables deep, it will stop going deeper. By default, depthLimit is 3.

This isn't recommended, but you can disable depthLimit by setting it to -1.

Last updated