Class pl.Set
A Set class.
> Set = require 'pl.Set'
> = Set{'one','two'} == Set{'two','one'}
true
> fruit = Set{'apple','banana','orange'}
> = fruit['banana']
true
> = fruit['hazelnut']
nil
> colours = Set{'red','orange','green','blue'}
> = fruit,colours
[apple,orange,banana] [blue,green,orange,red]
> = fruit+colours
[blue,green,apple,red,orange,banana]
> = fruit*colours
[orange]
Depdencies: pl.utils , pl.tablex , pl.class , (pl.List if __tostring is used)
Functions
Set.values (self) | get a list of the values in a set. |
Set.map (self, fn, ...) | map a function over the values of a set. |
Set.union (self, set) | union of two sets (also +). |
Set.intersection (self, set) | intersection of two sets (also *). |
Set.difference (self, set) | new set with elements in the set that are not in the other (also -). |
Set.issubset (self, set) | is the first set a subset of the second (also <)?. |
Set.isempty (self) | is the set empty?. |
Set.isdisjoint (s1, s2) | are the sets disjoint? |
Set.len (s) | size of this set (also # for 5.2). |
metamethods
Set:__tostring () | string representation of a set. |
Set.__add () | union of sets. |
Set.__mul () | intersection of sets. |
Set.__sub () | difference of sets. |
Set.__pow () | symmetric difference of sets. |
Set.__lt () | first set subset of second? |
Set.__len () | cardinality of set (5.2). |
Set.__eq (s1, s2) | equality between sets. |
Methods
pl.Set:Set (t) | create a set. |
Functions
- Set.values (self)
-
get a list of the values in a set.
Parameters:
- self a Set
- Set.map (self, fn, ...)
-
map a function over the values of a set.
Parameters:
- self a Set
- fn a function
- ... extra arguments to pass to the function.
Returns:
-
a new set
- Set.union (self, set)
-
union of two sets (also +).
Parameters:
- self a Set
- set another set
Returns:
-
a new set
- Set.intersection (self, set)
-
intersection of two sets (also *).
Parameters:
- self a Set
- set another set
Returns:
-
a new set
- Set.difference (self, set)
-
new set with elements in the set that are not in the other (also -).
Parameters:
- self a Set
- set another set
Returns:
-
a new set
- Set.issubset (self, set)
-
is the first set a subset of the second (also <)?.
Parameters:
- self a Set
- set another set
Returns:
-
true or false
- Set.isempty (self)
-
is the set empty?.
Parameters:
- self a Set
Returns:
-
true or false
- Set.isdisjoint (s1, s2)
-
are the sets disjoint? (no elements in common).
Uses naive definition, i.e. that intersection is empty
Parameters:
- s1 a Set
- s2 another set
Returns:
-
true or false
- Set.len (s)
-
size of this set (also # for 5.2).
Parameters:
- s a Set
Returns:
-
size
metamethods
- Set:__tostring ()
- string representation of a set.
- Set.__add ()
- union of sets.
- Set.__mul ()
- intersection of sets.
- Set.__sub ()
- difference of sets.
- Set.__pow ()
- symmetric difference of sets.
- Set.__lt ()
- first set subset of second?
- Set.__len ()
- cardinality of set (5.2).
- Set.__eq (s1, s2)
-
equality between sets.
Parameters:
- s1
- s2