val carMst: List<(Mutable)Map<String!, Any!>!>!
val carUserIds: List<(Mutable)Map<String!, Any!>!>!
....
....
val result = ArrayList<Car>()
for (mst in carMst) {
val userIds = ArrayList<Int>()
for (uids in carUserIds) {
if (mst["car_id"] == uids["car_id"]) {
userIds.add(uids["user_id"] as Int)
}
}
val car = Car(
mst["car_id"] as Int,
mst["model"] as String,
userIds
)
result.add(car)
}
i dont know too much about collection and lambda but with collection this can be more simple and beautiful right? 😀
thanks
s
Shawn
12/23/2019, 10:04 PM
is each
Map<String, Any>
representative of some kind of
Car
-related record stored somewhere? You should consider migrating from weakly-typed maps to something more explicit and harder to coerce improperly
Shawn
12/23/2019, 10:06 PM
is
if (carMst["car_id"] == uids["car_id"])
supposed to be
if (mst["car_id"] == uids["car_id"])
?
carMst
is a list here and cannot be accessed using a string
Shawn
12/23/2019, 10:06 PM
I’m not sure if this snippet even compiles tbh
Shawn
12/23/2019, 10:07 PM
the implied data model here seems complex and hard to advise on over the internet not gonna lie
Shawn
12/23/2019, 10:08 PM
I’m not saying there’s guaranteed to be a better than