Hey,
could anyone help me with something?
with the data class below:
data class Item(val completed: Boolean, val details: String? = null)
and a list:
val p = listOf(
Item(true, "one"),
Item(false, "two"),
Item(true, "three")
)
I need to transform this data (truncate the second value in the Item to return something like:
listOf(
Item(true, "o"),
Item(false, "t"),
Item(true, "t")
)
Im trying:
val p = listOf(
Item(true, "one"),
Item(false, "two"),
Item(true, "three")
)
println(p.map { (_,details) -> details?.take(1) })
but it returns: [o, t, t]
What’s the best way to do this in Kotlin?
Thank you in advance