SymmetricDifference returns the elements that need to be added and removed to get from set 'a' to set 'b'. Note that duplicates are ignored in sets. In classical set theory notation, SymmetricDifference returns all elements of {add} and {remove} together. It is more useful to return them as their ow
(a, b []T)
| 201 | // fmt.Println(add) // [2] |
| 202 | // fmt.Println(remove) // [3, 4] |
| 203 | func SymmetricDifference[T comparable](a, b []T) (add []T, remove []T) { |
| 204 | f := func(a, b T) bool { return a == b } |
| 205 | return SymmetricDifferenceFunc(a, b, f) |
| 206 | } |
| 207 | |
| 208 | func SymmetricDifferenceFunc[T any](a, b []T, equal func(a, b T) bool) (add []T, remove []T) { |
| 209 | // Ignore all duplicates |