Ahmed Sellami
10/06/2022, 1:25 PMvar playedPodcast = playedPodcasts.find {
it.id == itemToPlay?.id
}
if (playedPodcast == null) {
playedPodcasts.add(PlayedPodcast(itemToPlay?.id, mutableListOf()))
}
playedPodcast = playedPodcasts.find {
it.id == itemToPlay?.id
}!!
Christian Würthenr
10/06/2022, 1:37 PMplayedPodcasts
you can do
val playedPodcasts = mutableMapOf<String, Podcast>(...)
val playedPodcast = playedPodcasts.getOrPut(itemToPlay.id) {
PlayedPodcast(itemToPlay?.id, mutableListOf())
}
Christian Würthenr
10/06/2022, 1:39 PMval playedPodcasts = listFromBackend.associate { podcast -> podcast.id to podcast }.toMutableMap()
Ahmed Sellami
10/06/2022, 1:45 PMAhmed Sellami
10/06/2022, 1:47 PMChristian Würthenr
10/06/2022, 1:49 PMgetOrElse
on lists, but it wont add the value to the list. Your use case is just not suited for a list 😄 If you convert to a map every time you won't have the item in the map as well as you get a new map each time. Also might come with some performance impactChristian Würthenr
10/06/2022, 1:50 PMAhmed Sellami
10/06/2022, 1:54 PMDaniel Dawson
10/06/2022, 4:50 PM