luvit-set
Straightforward Lua Set library for Luvit
Install
- Download and install Node.js. Then you have
npm
- In the root of your Luvit project,
npm install luvit-set
Usage
Start off with
local Set = require("luvit-set")
Then, to create a set (of things you like):
local ilike = Set:new()
to add items to a set:
ilike:add("apples")ilike:add("bananas")
or, initialise with values on creation:
local ilike = Set:new({"apples", "bananas"})
Let's create another set:
local ulike = Set:new({"apples", "strawberries"})
Then we can:
local welike = ilike + ulike -- union: apples, bananas, strawberrieslocal webothlike = ilike * ulike -- intersection: appleslocal udontlike = ilike - ulike -- subtraction: bananas
Lastly, some conveniences:
local somethingilike = ilike:anelement()ilike:len() -- 2for k, _ in pairs(ilike) do print(k)endprint(ilike) -- '{"apples", "bananas"}'local list = ilike:tolist() -- {"apples", "bananas"}
Tests
npm test luvit-set
License
LGPL+; see the LICENSE
file