It creates a new list every time right? I forgot a...
# android
l
It creates a new list every time right? I forgot about
when
:
Copy code
destination.filterKeys { key ->
    when (key) {
      in list1, list2, list3 -> true
      else -> false
    }
}
I'm fine with this, if no one else has a more convenient solution
e
you mean
in list1, in list2, in list3 ->
right?
it would be equivalent to
key in list1 || key == list2 || key == list3
as you wrote it
if you had a lot of lists, then maybe
Copy code
listOf(list1, list2, list3).any { key in it }
would make sense. maybe not for just 3 of them, though
l
it would be equivalent to 
key in list1 || key == list2 || key == list3
 as you wrote it
if this is true, I made a mistake. Thanks for clarification @ephemient
v
Yep, same error as Brians solution
listOf(list1, list2, list3).all { key in it }
Optimally with the
listOf
outside the lambda
e
ah going back to previous conversation started in another thread, I see. yeah the
when
isn't going to do the right thing regardless
depends on various factors, but creating an intersection set up front may be a good idea
common = list1.toSet() intersect list2 intersect list3; key in common
for example
if you have more, it would be better to accumulate like common = list1.toMutableSet() common.retainAll(list2) common.retainAll(list3)
l
Thanks guys!