From 6fb8269c84498fa49d68faa017000123dcd00d8c Mon Sep 17 00:00:00 2001 From: Eugene Siegel Date: Wed, 18 Dec 2024 15:17:23 -0500 Subject: [PATCH] fn: add set copy method Copy --- fn/set.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fn/set.go b/fn/set.go index c3a3264708..faeb9d7df6 100644 --- a/fn/set.go +++ b/fn/set.go @@ -95,6 +95,15 @@ func (s Set[T]) ToSlice() []T { return maps.Keys(s) } +// Copy copies s and returns the result. +func (s Set[T]) Copy() Set[T] { + copy := make(Set[T]) + for e := range s { + copy.Add(e) + } + return copy +} + // SetDiff returns all the items that are in the first set but not in the // second. func SetDiff[T comparable](a, b []T) []T {