# ISet

> A persistent immutable set backed by a hash-array mapped trie.

Source: https://docs.pyrula.io/primitives/immutable-set/

`ISet` is an immutable set. Operations return a new `ISet` that shares structure with the original.

```python
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
```

## Set algebra

```python
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](https://docs.pyrula.io/primitives/collections.md#iteration-order).
