feat: helper instances for NameSet (#9529)

This PR upstreams some helper instances for `NameSet` from Batteries.

(These could be generalized to an arbitrary TreeSet, but I'll leave that
for someone else.)
This commit is contained in:
Kim Morrison 2025-07-25 19:33:19 +10:00 committed by GitHub
parent 5244ac3bb5
commit 0071bea64e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -58,6 +58,18 @@ def append (s t : NameSet) : NameSet :=
instance : Append NameSet where
append := NameSet.append
instance : Singleton Name NameSet where
singleton := fun n => (∅ : NameSet).insert n
instance : Union NameSet where
union := NameSet.append
instance : Inter NameSet where
inter := fun s t => s.foldl (fun r n => if t.contains n then r.insert n else r) {}
instance : SDiff NameSet where
sdiff := fun s t => t.foldl (fun s n => s.erase n) s
/-- `filter f s` returns the `NameSet` consisting of all `x` in `s` where `f x` returns `true`. -/
def filter (f : Name → Bool) (s : NameSet) : NameSet := Std.TreeSet.filter f s