val benefit = contentProperties.tariffBenefits.getValue(it) BenefitExtendedDto( id = it,…
- User
val benefit = contentProperties.tariffBenefits.getValue(it) BenefitExtendedDto( id = it, title = benefit.title, icon = benefit.icon, category = benefit.category, subtitle = benefit.subtitle )
create extension fun from selected text
- Assistant
You can create an extension function on the type of
it(assuming it's a key of the maptariffBenefits) that accepts the map and returns the constructedBenefitExtendedDto. Based on the selected code,itis the key,contentProperties.tariffBenefitsis a map from key to some value type that containstitle,icon,category,subtitle.Let me assume the following:
itis of typeKtariffBenefitsis of typeMap<K, Benefit>
Here's the extension function for
Kthat, given a mapMap<K, Benefit>, returns the dto:fun <K> K.toBenefitExtendedDto(tariffBenefits: Map<K, Benefit>): BenefitExtendedDto { val benefit = tariffBenefits.getValue(this) return BenefitExtendedDto( id = this, title = benefit.title, icon = benefit.icon, category = benefit.category, subtitle = benefit.subtitle ) }