oday
05/25/2021, 2:19 PMid
exists in the list of ordersoday
05/25/2021, 2:20 PMcars.filter { it.id in orders }
?diesieben07
05/25/2021, 2:22 PMorders
is a list of car IDs - yes.oday
05/25/2021, 2:24 PModay
05/25/2021, 2:24 PMiterator()
or another find or something?oday
05/25/2021, 2:24 PMMartin Cazares
05/25/2021, 2:26 PMdiesieben07
05/25/2021, 2:44 PMcars.filter { car -> orders.any { order -> order.carId == car.id } }
Or as Martin says, first make a set of car ids from all orders, if this is performance critical code.oday
05/25/2021, 3:23 PMany
thank you that does itoday
05/27/2021, 12:29 PModay
05/27/2021, 12:29 PMcar.order = order
oday
05/27/2021, 12:30 PM.map
after the filter doesn’t grant me the order, i just get the car of courseoday
05/27/2021, 12:30 PM.any
Ithinkoday
05/27/2021, 12:32 PMcar.copy(order = neworder)
lateroday
05/27/2021, 12:49 PMfor (result in listings.results) {
for (order in orders) {
if (result.id == order.listingId) {
purchasedCars.add(
result.copy(
order = order,
contactOptions = emptyList(),
isFavorite = true
)
)
}
}
}
oday
05/27/2021, 12:49 PModay
05/27/2021, 12:49 PMany
, in the same chaindiesieben07
05/27/2021, 3:29 PMlistings.results.flatMapTo(purchasedCars) { result ->
orders.mapNotNull { order ->
if (result.id == order.listingId) {
result.copy(...)
} else null
}
}
or something like thatdiesieben07
05/27/2021, 3:30 PM