From fc06362295bdc26b976ef916ad272b4efbb6cb79 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Mon, 2 Jun 2025 20:14:22 +0100 Subject: [PATCH] set: introduce set difference Change-Id: soqmukrvportotypoxnrtulytlllznxm Signed-off-by: oppiliappan --- set.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/set.go b/set.go index 2698c91..81788c0 100644 --- a/set.go +++ b/set.go @@ -44,3 +44,14 @@ func (s Set[T]) Intersection(other Set[T]) Set[T] { } return result } + +// Difference returns a new set with elements in s but not in other. +func (s Set[T]) Difference(other Set[T]) Set[T] { + result := New[T]() + for k := range s { + if _, ok := other[k]; ok { + result.Add(k) + } + } + return result +} -- 2.43.0