ISet
ISet is an immutable set. Operations return a new ISet that shares structure with the original.
from pyrula import ISet
s = ISet([1, 1, 2, 3]) # any iterable; duplicates droppeds.size() # 3s.add(4) # new ISet; s is unchangeds.remove(9) # no-op for absent elements2 in s # Trues.contains(2) # TrueISet().is_empty() # TrueSet algebra
Section titled “Set algebra”a = ISet([1, 2, 3])b = ISet([2, 3, 4])
a.union(b) # ISet({1, 2, 3, 4})a.intersection(b) # ISet({2, 3})a.difference(b) # ISet({1})ISet([1, 2]).is_subset_of(a) # True
a.filter(lambda x: x % 2 == 1) # ISet({1, 3})a.map(lambda x: x * 10) # ISet({10, 20, 30}), deduplicateda.to_set() # plain seta.to_ilist() # IList in iteration orderEquality ignores order: ISet([3, 1, 2]) == ISet([1, 2, 3]). Iteration order is fixed by contents, not insertion; see Collections.