https://kotlinlang.org logo
#arrow
Title
c

carbaj0

09/15/2023, 5:46 PM
is there a better way to do this?
Copy code
chipGroup.list transform {
    it.map { chip ->
        when (chip) {
            is FilterChip.All -> chip.copy(selected = filterChip == chip)
            is FilterChip.Finance -> chip.copy(selected = filterChip == chip)
            is FilterChip.Investment -> chip.copy(selected = filterChip == chip)
            is FilterChip.Saving -> chip.copy(selected = filterChip == chip)
            is FilterChip.Other -> chip.copy(selected = filterChip == chip)
        }
    }
}

@optics
data class ChipGroup(
    val list: List<FilterChip>,
    val onChange: (FilterChip) -> Unit,
) {
    companion object
}

@optics
sealed interface FilterChip {
    val title: String
    val selected: Boolean

...
}
a

Alejandro Serrano.Mena

09/16/2023, 1:07 PM
not as of now, we haven't implemented yet lifting properties from the parent class of a sealed hierachy as lenses...
KopyKat does have that feature https://kopyk.at/#copy-for-sealed-hierarchies
c

carbaj0

09/17/2023, 7:01 PM
👍
s

simon.vergauwen

09/18/2023, 6:25 AM
Ah, have we still not added that 😅 I thought we already did at some point, the issue has been open for years 😕
6 Views