Skip to content
Pyrula
Pre-release: the packages are not on PyPI yet, so pip install does not resolve. Build from source to try it today.

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 dropped
s.size() # 3
s.add(4) # new ISet; s is unchanged
s.remove(9) # no-op for absent elements
2 in s # True
s.contains(2) # True
ISet().is_empty() # True
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}), deduplicated
a.to_set() # plain set
a.to_ilist() # IList in iteration order

Equality ignores order: ISet([3, 1, 2]) == ISet([1, 2, 3]). Iteration order is fixed by contents, not insertion; see Collections.

View this page as Markdown