Mental Model
- Immutable: All operations return new HashSets without mutating the original
- Unique values: Duplicates are automatically removed
- Hash-based: Uses
Hash.hash()andEqual.equals()for values - O(log n) add, remove, and contains
- Unordered: Iteration order is not guaranteed
Key Operations
Create
Build HashSets from values:Query
Check membership and size:Transform
Add or remove elements:Map
Transform values:Filter
Select elements:Fold
Reduce to a single value:Combine
Set operations:Iterate
Loop over values:Type Signatures
Custom Equality
ImplementEqual and Hash for custom types:
