Is there an elegant / idiomatic way to check in Kotlin whether an element of one list is contained in another list?
Given:
val listA = listOf("A", "B", "C")
I can write expressions such as:
listA.intersect(setOf("E", "C")).isNotEmpty()
or:
listA.any { it in listOf("E","C") }
That's OK, but I wonder if there is even a more fluent way to express that (as this code is simplified, the real code is more complex).
My fallback is to use a custom extension function, e.g.:
fun <T> List<T>.containsAny(vararg other : T) =
this.intersect(other.toSet()).isNotEmpty()
I just wonder if there is a better way.