So this getLocalizedTitle()
function I have for this 3 type of classes, should I have as utils and pass titles to this function or there can be nicer solution with extensions?
data class Carousel(val id: String, val titles: List<Title>) : ContentItem()
data class HeroBanner(val titles: List<Title>,
val descriptions: List<Description>,
val images: List<Image>, val id: String) : ContentItem()
}
data class MenuItem(val type: String, val titles: List<Title>, val actionType: String, val pageComponents: List<PageComponent>) :
fun getLocalizedTitle(locale: String): Title? {
val titles = titles.filter { it.locale == locale }
return if (titles.isNotEmpty()) {
titles[0]
} else {
null
}
}