Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Figured it out, I was thinking too complicated.
I have List l2 = l1.map(...)
Now I received a subset of l2 elements and wanted the corresponding l1 elements. Like:
l1.filter(el -> subset.any(s -> s.id == el.id)) -
Nevoic1996yA mapping would be more performant, and depending on the domain, make more sense.
(Referring to the data structure not the method). -
Nevoic1996yI.E:
Assuming:
list1: List<T : ObjectWithID>
list2: List<Integer> // if IDs are ints
Then:
val idToObj = list1.map { it.id to it }.toMap()
val selected = list2.map { idToObject.get(it) }
Related Rants
In Kotlin or Java, I have a list of items that have an ID property. This list is generated based on another list. Now I get a List of mentioned list items and I want to select all items in the parent list, selecting by ID equality.
Is there a more elegant way than just iterating the parent lost for each derived item? Thank you :)
question
java
kotlin
kotlin java android