I want to be able to check that collection a contains exactly all of the elements of b, but an equality based check is not sufficient; for example:
data class Person(val name: String, val age: Int)
val a = listOf(Person("Alice", 10), Person("Bob", 13))
val b = listOf(Person("Alice", 10), Person("Alice", 10))
fun main() {
println(a.containsAll(b))
}
true
Whilst this is technically true, it's not the result I want, because a only contains one Person("Alice", 10), whereas b contains two of them.
The above example should fail, whilst the below should pass.
data class Person(val name: String, val age: Int)
val a = listOf(Person("Alice", 10), Person("Alice", 10), Person("Bob", 13))
val b = listOf(Person("Alice", 10), Person("Alice", 10))
fun main() {
println(a.containsAllExact(b))
}
Is there a way to do this?