String repr for Set

This commit is contained in:
Kovid Goyal 2023-02-20 17:18:31 +05:30
parent 57839b4e03
commit 12c8af60dc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -4,6 +4,8 @@ package utils
import ( import (
"fmt" "fmt"
"golang.org/x/exp/maps"
) )
var _ = fmt.Print var _ = fmt.Print
@ -22,6 +24,10 @@ func (self *Set[T]) AddItems(val ...T) {
} }
} }
func (self *Set[T]) String() string {
return fmt.Sprintf("%#v", maps.Keys(self.items))
}
func (self *Set[T]) Remove(val T) { func (self *Set[T]) Remove(val T) {
delete(self.items, val) delete(self.items, val)
} }