A small library with useful methods to handle Lua's table when it's working like an Array
To install array, run:
$ luarocks install arrayOr simply copy the array.lua file and paste in your project.
-
array.
is_array(object:table):boolean
Checks if table is an Array -
array.
is_empty(object:table):boolean
Checks if table is empty -
array.
slice(object:table, start:number, end:number):table
Returns a shallow copy of a portion of a table into a new table -
array.
index_of(object:table, value:*):number
Returns the index at which value can be found or -1 if value is not present -
array.
reverse(object:table):table
Creates a new table with reverse values -
array.
first(object:table):*
Returns the first value in a table -
array.
last(object:table):*
Returns the last value in a table -
array.
max(object:table):*
Returns the maximum value in a table -
array.
min(object:table):*
Returns the minimum value in a table -
array.
map(object:table, callback:function):table
Creates a new table of values by mapping each value in list through a transformation function -
array.
filter(object:table, callback:function):table
Produces a new table containing all elements that pass truth test -
array.
reduce(object:table, callback:function [, memo]):*
Applies a function against an accumulator and each value of the table to reduce it to a single value -
array.
concat(object:table, object:table):table
Returns a new table by joining all values from the two tables -
array.
uniq(object:table):table
Returns a new table by removing duplicates values -
array.
without(object:table, object:table):table
Returns a copy of the table with all instances of the values removed -
array.
some(object:table, callback:function):boolean
Tests whether at least one element in the table passes the test implemented by the callback -
array.
every(object:table, callback:function):boolean
Tests whether all elements in the table passes the test implemented by the callback -
array.
zip(object:table, object:table):table
Returns a table of the two supplied by pairing up equally-positioned elements from both tables -
array.
shallow_copy(object:table):table
Returns a shallow copy of the table passed as parameter -
array.
deep_copy(object:table):table
Returns a deep copy of the table passed as parameter -
array.
diff(object:table, object:table):table
Returns a new table with the items which exist only in the first table