lua-set

Straightforward Set library for Lua; creating and manipulating sets, including + (union), - (subtraction), * (intersection), len(), and tostring()

npm install lua-set
2 downloads in the last week
2 downloads in the last month

LuaRock "set"

Straightforward Set library for Lua

Install

Set is a listed LuaRock. Install using LuaRocks: luarocks install set

Dependencies

Set depends on Lua 5.2. lunitx is needed to run the tests and will be installed if not present

Usage

Start off with

require("luarocks.loader")
local Set = require("Set")

Then, to create a set:

local ilike = Set:new()

to add items to a set:

ilike:add("apples")
ilike:add("bananas")

or, we could have done:

local ilike = Set:new({"apples", "bananas"})

Let's have another set:

local ulike = Set:new({"apples", "strawberries"})

Then we can:

local welike     = ilike + ulike -- union:        apples, bananas, strawberries
local webothlike = ilike * ulike -- intersection: apples
local udontlike  = ilike - ulike -- subtraction:  bananas

Lastly, some conveniences:

ilike:len()  -- 2
local somethingilike = ilike:anelement()
print(ilike) -- {"apples", "bananas"}

Tests

See ./tst/init.lua

License

LGPL+; see ./doc/LICENSE

npm loves you