Add Peek method to Set

This commit is contained in:
Hanzo Dev
2025-10-30 12:33:06 -07:00
parent c25b6e7f89
commit 84ce29ae02
+10
View File
@@ -171,3 +171,13 @@ func (s *Set[T]) UnmarshalJSON(data []byte) error {
return nil
}
// Peek returns a random element from the set.
// If the set is empty, returns the zero value and false.
func (s Set[T]) Peek() (T, bool) {
for elt := range s {
return elt, true
}
var zero T
return zero, false
}