|
@@ -45,3 +45,30 @@ func ExtractValue[T any, R any](s []T, addTo func(v T) (R, bool)) []R {
|
|
|
|
|
|
return retSlice
|
|
return retSlice
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func ExtractIntersectionValue[T comparable](aList, bList []T) []T {
|
|
|
|
+ aList = RemoveRepeatElement(aList)
|
|
|
|
+ bList = RemoveRepeatElement(bList)
|
|
|
|
+ cList := make([]T, 0)
|
|
|
|
+
|
|
|
|
+ tmpMap := make(map[T]int)
|
|
|
|
+ for _, item := range aList {
|
|
|
|
+ tmpMap[item] = 0
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for _, item := range bList {
|
|
|
|
+ if _, ok := tmpMap[item]; ok {
|
|
|
|
+ cList = append(cList, item)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return cList
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func ExtractUnionValue[T comparable](aList, bList []T) []T {
|
|
|
|
+ cList := make([]T, 0)
|
|
|
|
+ cList = append(cList, aList...)
|
|
|
|
+ cList = append(cList, bList...)
|
|
|
|
+ cList = RemoveRepeatElement(cList)
|
|
|
|
+ return cList
|
|
|
|
+}
|