unique_array classmod

Unique Array class For working with unique string array values.

Creates an array with hash/dictionary indexing. Adding or removeing values without using the provided methods can break the functionality of this class. Additional methods exported by requering unique_array are .set and .make_dictionary

Usage

local Unique_Array = require('__stdlib__/stdlib/utils/classes/unique_array')
local my_array = Unique_Array('first')
my_array:add('second')
if my_array['second'] then
  print('its truthy')
end'

Methods

unique_array:new(...) Create a new unique array.
unique_array:add(other) Add a string to the array if it doesn’t exist in the array.
unique_array:remove(other) Remove the strings from the array if they exist.
unique_array:toggle(other) Toggles the passed name in the array by adding it if not present or removing it if it is.
unique_array:diff(other) Get all items that are NOT in both arrays.
unique_array:intersects(other) Get all items that are in both arrays.
unique_array:sort([cmp]) Sort the unique_array in place.
unique_array:concat(other) Create a new unique_array by concatenating together.
unique_array:find(pattern) Find all members in a unique array that match the pattern.
unique_array:clear() Clear the array returning an empty array object

Functions

unique_array:all(other) Does this array have all of the passed strings.
unique_array:any(other) Does this array have any of the passed strings.
unique_array:none(other) Does this array have none of the passed strings.
unique_array:same(other) Do both arrays contain the same items
unique_array:disjointed(other) Do the unique arrays have no items in common
unique_array:tostring() Convert the array to a string.
unique_array:make_dictionary([func][, ...]) Return a dictionary mapping of the array.

Exports

unique_array.exports These functions are available when requiring this class.

Methods

# unique_array:new(...)

Create a new unique array.

Parameters:
  • ... : (unique_array, string or {string,...}) strings to initialize the unique array with
Returns:
  • new
# unique_array:add(other)

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

Parameters: Returns:
  • self
# unique_array:remove(other)

Remove the strings from the array if they exist.

Parameters: Returns:
  • self
# unique_array:toggle(other)

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

Parameters: Returns:
  • self
# unique_array:diff(other)

Get all items that are NOT in both arrays.

Parameters: Returns:
  • new
# unique_array:intersects(other)

Get all items that are in both arrays.

Parameters: Returns:
  • new
# unique_array:sort([cmp])

Sort the unique_array in place.

Parameters:
  • cmp : (function) Comparator sort function to use (optional)
Returns:
  • self
# unique_array:concat(other)

Create a new unique_array by concatenating together.

Parameters: Returns:
  • new
# unique_array:find(pattern)

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

Parameters: Returns:
  • new unique array containing all elements that match.
# unique_array:clear()

Clear the array returning an empty array object

Returns:
  • self

Functions

# unique_array:all(other)

Does this array have all of the passed strings.

Parameters: Returns:
  • (boolean) every passed string is in the array
# unique_array:any(other)

Does this array have any of the passed strings.

Parameters: Returns:
  • (boolean) any passed string is in the array
# unique_array:none(other)

Does this array have none of the passed strings.

Parameters: Returns:
  • (boolean) no passed strings are in the array
# unique_array:same(other)

Do both arrays contain the same items

Parameters: Returns:
# unique_array:disjointed(other)

Do the unique arrays have no items in common

Parameters: Returns:
# unique_array:tostring()

Convert the array to a string.

Returns:
# unique_array:make_dictionary([func][, ...])

Return a dictionary mapping of the array.

can be passed a function to set the value of the field.

Parameters:
  • func : (function) value, index are passed as the first two paramaters (optional)
  • ... : (any) additional values to pass to the function (optional)
Returns:
  • (dictionary)

Exports

# unique_array.exports

These functions are available when requiring this class.

Fields: