https://kotlinlang.org logo
#getting-started
Title
# getting-started
d

Dan O'Brien

09/07/2020, 2:19 PM
does anyone have any suggestions for how to handle comparing 2 similar(but not exact) lists. I want to compare the objects in list(generally in same position in either list) A by
key
against list B, and then by a
version
. If value in list B is higher than list A, I want to replace list A with item from list B. I think
compareValuesBy
might work but I’m having trouble sorting out how to implement it fully because elements might be slightly different so I’ll need to scan the list to verify if it’s not found
n

nfrankel

09/07/2020, 3:04 PM
do both lists have the same number of elements? if yes, i’ll start with
zip
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/zip.html then you can do whatever you want with the pairs
d

Dan O'Brien

09/07/2020, 5:12 PM
no they won’t reliably, items will be added/removed from List B, it’s performing an API call that’s then comparing to List A to update it in place
2 Views