https://kotlinlang.org logo
#codereview
Title
# codereview
h

Harun

07/24/2019, 12:04 PM
Any ideas to make this code more idiomatic?
b

bezrukov

07/24/2019, 12:17 PM
1.
sessionSpeakerIdList.forEach { speakerId ->
seems unused, moreover you will add duplicates to sessionModel.speakerList 2. Why
sessionList.map
? It converts your list to List<Unit>. you can use onEach, if you just want to apply op on each item
It can be something like that:
Copy code
val speakerById :List<SpeakersModel> = getSpeakersInfo().associateBy { it.id }
val sessionList : List<SessionsModel> = snapshots.toObjects<SessionsModel>()
sessionList.onEach { sessionModel ->
    sessionModel.speakerList = sessionModel.speaker_id.mapNotNull {speakerById[it]}
            }
h

Harun

07/24/2019, 12:22 PM
sessionSpeakerIdList.forEach{speakerId ->}
am getting an array of speakerId and for eachbid am getting the speaker details
b

bezrukov

07/24/2019, 12:23 PM
You don't use
speakerId
then
h

Harun

07/24/2019, 12:26 PM
Seen from your example, thanks for the help
3 Views