delblanco
10/21/2020, 10:37 AMlistOf(A,B,C)
I would like to end up with the following pairs: A to B, A to C, B to C
Currently I got something like this but it feels non-idiomatic and inefficient...
val users = listOf(User("A"), User("B"), User("C"))
val chats = users.flatMap{ u1 ->
users.filterNot { u1 == it }
.map { u2 -> Chat(setOf(u1, u2)) }
}.toSet() // filters out duplicates
bjonnh
10/22/2020, 7:27 PMbjonnh
10/22/2020, 7:33 PMval l = listOf("A", "B", "C", "D")
l.flatMapIndexed { i, a ->
l.subList(i+1, l.size).map { setOf(a,it) }
}
bjonnh
10/22/2020, 7:36 PMdelblanco
10/27/2020, 10:50 AMfilterNot
nor the toSet
to filter duplicates
thanks!