Page 1 of 1

array - a library for tables

Posted: Tue Sep 14, 2021 9:45 am
by Rick Astley
This library is a useful collection of functions to work with Lua tables in a array fashion. There are other libraries around which have the same intent, and this one does not aim to outclass them.

A quick example

Code: Select all

array = require 'array'

-- create an array object from a set of items
a = array.from(0,2,4,6,8) -- a: {0,2,4,6,8}
-- create an array object using a function
b = array.new(function(index) return index*2 - 1 end, 5) -- b: {1,3,5,7,9}

-- tables created by the module support OOP
c = a:fusion(function(a, b) return a < b end, b) -- c: {1,2,3,4,...,8,9}

-- but you can work with pure tables as well
array.print({'Hi','Hello','Bye'}) -- output: [Hi, Hello, Bye]
There are a lot of functions, so if you are inspired check out the official repo which features the full list of them.
On the GitHub repository you will find a complete documentation with examples for each function. I hope you'll enjoy :3
https://github.com/rick4stley/array