Kryzeth Standard Library

StdLib.UniqueArray

Unique Array class For working with unique string array values. Creates an array with hash/dictionary indexing.

@usage local uniquearray = require('_krystdlib_/stdlib/utils/classes/unique_array') local myarray = uniquearray('first') my_array:add('second') if my_array['second'] then print('its truthy') end' @set all=true

Methods18

function UniqueArray.new(...: StdLib.UniqueArray | string | string[]) -> new StdLib.UniqueArray

Create a new unique array.

Parameters
...StdLib.UniqueArray | string | string[]

} strings to initialize the unique array with

Returns
function UniqueArray.add(other: StdLib.UniqueArray | string | string[]) -> self StdLib.UniqueArray

Add a string to the array if it doesn't exist in the array.

Parameters
otherStdLib.UniqueArray | string | string[]

}

Returns
function UniqueArray.remove(other: StdLib.UniqueArray | string | string[]) -> self StdLib.UniqueArray

Remove the strings from the array if they exist.

Parameters
otherStdLib.UniqueArray | string | string[]

}

Returns
function UniqueArray.toggle(other: StdLib.UniqueArray | string | string[]) -> self StdLib.UniqueArray

Toggles the passed name in the array by adding it if not present or removing it if it is.

function UniqueArray.diff(other: StdLib.UniqueArray | string | string[]) -> new StdLib.UniqueArray

Get all items that are NOT in both arrays.

Parameters
otherStdLib.UniqueArray | string | string[]

}

Returns
function UniqueArray.intersects(other: StdLib.UniqueArray | string | string[]) -> new StdLib.UniqueArray

Get all items that are in both arrays.

Parameters
otherStdLib.UniqueArray | string | string[]

}

Returns
function UniqueArray.sort(cmp: nil | function) -> self StdLib.UniqueArray

Sort the UniqueArray in place.

Parameters
cmpnil | function

[opt] Comparator @{sort} function to use

Returns
function UniqueArray.concat(other: StdLib.UniqueArray | string | string[]) -> new StdLib.UniqueArray

Create a new UniqueArray by concatenating together.

function UniqueArray.find(pattern: string) -> new StdLib.UniqueArray

Find all members in a unique array that match the pattern.

Parameters
patternstring

Lua @{pattern}

Returns
newStdLib.UniqueArray

unique array containing all elements that match.

function UniqueArray.clear() -> self StdLib.UniqueArray

Clear the array returning an empty array object

function UniqueArray.all(other: StdLib.UniqueArray | string | string[]) -> every boolean

Does this array have all of the passed strings.

Parameters
otherStdLib.UniqueArray | string | string[]

}

Returns
everyboolean

passed string is in the array

function UniqueArray.has(other: StdLib.UniqueArray | string | string[]) -> every boolean
Parameters
otherStdLib.UniqueArray | string | string[]

}

Returns
everyboolean

passed string is in the array

function UniqueArray.any(other: StdLib.UniqueArray | string | string[]) -> any boolean

Does this array have any of the passed strings.

Parameters
otherStdLib.UniqueArray | string | string[]

}

Returns
anyboolean

passed string is in the array

function UniqueArray.none(other: StdLib.UniqueArray | string | string[]) -> no boolean

Does this array have none of the passed strings.

Parameters
otherStdLib.UniqueArray | string | string[]

}

Returns
noboolean

passed strings are in the array

function UniqueArray.same(other: StdLib.UniqueArray | string | string[]) -> boolean

Do both arrays contain the same items

Parameters
otherStdLib.UniqueArray | string | string[]

}

Returns
boolean
function UniqueArray.disjointed(other: StdLib.UniqueArray | string | string[]) -> boolean

Do the unique arrays have no items in common

Parameters
otherStdLib.UniqueArray | string | string[]

}

Returns
boolean
function UniqueArray.tostring() -> string

Convert the array to a string.

function UniqueArray.make_dictionary(func: nil | function, ...: any[opt]) -> { [any]: any }

Return a dictionary mapping of the array. can be passed a function to set the value of the field.

Parameters
funcnil | function

[opt] value, index are passed as the first two paramaters

...any[opt]

additional values to pass to the function

Returns
{ [any]: any }

Fields1

UniqueArray.__class: string = "UniqueArray"