Is there a more idiomatic way to do the following ...
# announcements
p
Is there a more idiomatic way to do the following operation? Thank you!
it.receiver
can either be of type ABC or DEF. If its ABC, collect to the first list, if its DEF, collect to the second list
Copy code
val payments = findOpenPayments.get()
                .groupBy { it.receiver == "ABC" }

        val somePayments = payments.filter { it.key }.flatMap { it.value }
        val otherPayments = payments.filter { !it.key }.flatMap { it.value }
s
You can do something like this,
Copy code
val payments = findOpenPayments.get()
                .groupBy { it.receiver }
This will result in a HashMap of 2 keys
ABC
and
DEF
, from which you can obtain the value. Hope this helps
p
perfect. Thanks!
👍 1
s
if there are only two possible values for
receiver
, you can do
Copy code
val (somePayments, otherPayments) = openPayments
    .partition { it.receiver == "ABC" }
👀 1
s
Yep this works as well
p
That's also a great one. Thank you!