Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wscherphof/luvit-set
Straightforward Lua Set library for Luvit
https://github.com/wscherphof/luvit-set
Last synced: about 1 month ago
JSON representation
Straightforward Lua Set library for Luvit
- Host: GitHub
- URL: https://github.com/wscherphof/luvit-set
- Owner: wscherphof
- License: other
- Created: 2014-02-12T08:03:33.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-02-13T05:39:10.000Z (almost 11 years ago)
- Last Synced: 2024-10-05T02:06:33.424Z (about 1 month ago)
- Language: Lua
- Homepage:
- Size: 145 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#luvit-set
Straightforward [Lua](http://www.lua.org/) Set library for [Luvit](http://luvit.io/)##Install
- Download and install [Node.js](http://nodejs.org/download/). Then you have `npm`
- In the root of your Luvit project, `npm install luvit-set`##Usage
Start off with
```lua
local Set = require("luvit-set")
```
Then, to create a set (of things you like):
```lua
local ilike = Set:new()
```
to add items to a set:
```lua
ilike:add("apples")
ilike:add("bananas")
```
or, initialise with values on creation:
```lua
local ilike = Set:new({"apples", "bananas"})
```
Let's create another set:
```lua
local ulike = Set:new({"apples", "strawberries"})
```
Then we can:
```lua
local welike = ilike + ulike -- union: apples, bananas, strawberries
local webothlike = ilike * ulike -- intersection: apples
local udontlike = ilike - ulike -- subtraction: bananas
```
Lastly, some conveniences:
```lua
local somethingilike = ilike:anelement()
ilike:len() -- 2
for k, _ in pairs(ilike) do
print(k)
end
print(ilike) -- '{"apples", "bananas"}'
local list = ilike:tolist() -- {"apples", "bananas"}
```##Tests
`npm test luvit-set`##License
LGPL+; see the `LICENSE` file