fun Set<T>.difference(other: Set<T>): Set<T>
{
return subtrack(other) + other.subtrack(this)
}
s
Shawn
04/06/2019, 12:20 PM
looking at the docs for that
Sets.difference()
method, it doesn’t seem like it works like your code snippet:
>>
The returned set contains all elements that are contained by set1 and not contained by set2. set2 may also contain elements not present in set1; these are simply ignored.
Shawn
04/06/2019, 12:20 PM
Set.subtract()
seems to already fulfill this requirement
t
turansky
04/06/2019, 12:25 PM
@Shawn thank you
👍 1
s
Shawn
04/06/2019, 12:28 PM
the difference extension method you wrote looks more like a
symmetricDifference
method, which I don’t believe Kotlin provides
Shawn
04/06/2019, 12:28 PM
Guava does have a method that takes care of that, however