So I’m trying to build a map from 3 different lists and I am using this code here:
map = categories!!.groupBy { it.id }
.mapValues {
list1!!.filter { a ->
list2!!.any { a.id == it.id } && a.category_id == it.key
}
}.toMutableMap()
So it goes like this:
- list1 contains object1 which has the category id and an id
- list2 contains object2 which has only the id and not the category id
- The keys needs to be the category ids
- The values are the elements of list1 that have the same ids of the elements of list2
- Multiple elements can be in one category
- The end result is like this: Map
>
There is quite a lot of data to go through and right now it takes somewhere between 30sec to 1min on my phone to execute (in a coroutine).
submitted by /u/alexchaoss
[link] [comments]