If you create a builder — e.g., by using Podcast.builder().applyFrom(Podcast) — you have no way to manipulate its internal list of builders for its items. For example, you can add new episodes (always at the end of the list, after the existing ones) but there's no way to sort them, or filter them, before building.
The only option right now is to build the podcast, hoping it does build, and then use copy to manipulate the items:
val podcast = podcastBuilder.build()?.run {
// Sort episodes by pubDate, from newest to oldest
copy(episodes = episodes.sortedByPubDateDescending())
} ?: error("Unable to generate podcast feed")
It's not a very elegant way to do it.
If you create a builder — e.g., by using
Podcast.builder().applyFrom(Podcast)— you have no way to manipulate its internal list of builders for its items. For example, you can add new episodes (always at the end of the list, after the existing ones) but there's no way to sort them, or filter them, before building.The only option right now is to build the podcast, hoping it does build, and then use
copyto manipulate the items:It's not a very elegant way to do it.