Kotlin: Set/List elegant way to check if contains any value of another Set/List?
Is there an elegant / idiomatic way to check in Kotlin whether an element of one set is contained in another set?
Given:
val setA = setOf("A", "B", "C")
val setB = setOf("E", "C")
I can write expressions such as:
setA.intersect(setB).isNotEmpty()
or:
setA.any { it in setB }
But none of them is really a code being read fluently.
My fallback is to use a custom extension function, e.g.:
fun Set.containsAny(vararg other : T) =
this.intersect(other.toSet()).isNotEmpty()
I just...