Is there a short/idiomatic way to iterate through every pair of elements in a collection?
Even better would be a method that iterates through all fixed-cardinality subsets of a collection.
The classic and ugly approach would be:
val s = setOf(1, 2, 3, 4)
for (i in s) {
for (j in s) {
if (i != j) {
println("$i $j")
}
}
}
For having bigger subsets, more loops are necessary, so this isn't scalable.