From df2f3ff0d542e6a6df8db12f99f1ccfbe242fde0 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Mon, 2 Jun 2025 20:14:22 +0100 Subject: [PATCH] set: introduce set union Change-Id: mksqzkvmmntrpwzyzvlznxtlmqttzkuo Signed-off-by: oppiliappan --- set.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/set.go b/set.go index 2b0fe8d..eca34a3 100644 --- a/set.go +++ b/set.go @@ -21,3 +21,15 @@ func (s Set[T]) Remove(value T) { func (s Set[T]) Size() int { return len(s) } + +// Union returns a new set containing all elements from s and other. +func (s Set[T]) Union(other Set[T]) Set[T] { + result := New[T]() + for k := range s { + result.Add(k) + } + for k := range other { + result.Add(k) + } + return result +} -- 2.43.0