In Swift, I would like to make an extension on Set that takes two arrays, and the function needs to add the elements from one array and remove elements found in another array to the called upon Set.
extension Set {
mutating func update<T>(adding a:[T], removing b:[T]) where T:Hashable {
var r = union(Set<T>(a)) // ERROR: Type of expression is ambiguous without a type annotation
r.subtract(Set<T>(b))
self = r
}
}
I currently get this error: Type of expression is ambiguous without a type annotation
.
How can I fix this so that the Set instance I call this on will update accordingly?