From 709c315bc4d78518a303e55f16c80c58397b3773 Mon Sep 17 00:00:00 2001 From: Mathieu Fenniak Date: Tue, 14 Oct 2025 10:20:00 -0600 Subject: [PATCH] chore: add new functions to container.Set --- modules/container/set.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/container/set.go b/modules/container/set.go index d3719dc552..6535d1e4bd 100644 --- a/modules/container/set.go +++ b/modules/container/set.go @@ -79,3 +79,22 @@ func (s Set[T]) Seq() iter.Seq[T] { func (s Set[T]) Clone() Set[T] { return maps.Clone(s) } + +// Computes the elements that are in this set, that aren't in the other set. +func (s Set[T]) Difference(other Set[T]) Set[T] { + result := make(Set[T]) + for key := range s { + if !other.Contains(key) { + result.Add(key) + } + } + return result +} + +func (s Set[T]) Slice() []T { + retval := make([]T, 0, len(s)) + for key := range s { + retval = append(retval, key) + } + return retval +}