array - a library for tables

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Rick Astley
Prole
Posts: 16
Joined: Sat Mar 13, 2021 11:51 am

array - a library for tables

Post 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

Code: Select all

if self.thoughts[1] == 'give you up' then
   table.remove(self.thoughts,1)
end
 
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests