manlan
06/29/2020, 9:09 AMSackCastellon
06/29/2020, 9:12 AMlist.groupBy { it.type }.values
Tibi Csabai
06/29/2020, 9:34 AMmanlan
06/29/2020, 10:38 AMmanlan
06/29/2020, 10:46 AMdiesieben07
06/29/2020, 10:48 AMmanlan
06/29/2020, 11:16 AMMichael de Kaste
06/29/2020, 1:27 PMitems.fold(mutableListOf<MutableList<Item>>()) { acc, item ->
acc.apply {
when (lastOrNull()?.last()?.type) {
item.type -> last().add(item)
else -> add(mutableListOf(item))
}
}
}
however, I'm really sad that you can't destructure from the back of a listmanlan
06/29/2020, 5:01 PMmanlan
06/30/2020, 3:33 AMMichael de Kaste
06/30/2020, 9:03 AMlastOrNull()?.last()?
and another last()
with pattern matching or something else I could have maybe wrote acc as:
lists = (_*, lastList = (_*, lastItem))
to get:
lists.apply{
when(lastItem?.type){
item.type -> lastList.add(item)
else -> add(mutableListOf(item))
}
}
which just reads better 🙂Michael de Kaste
06/30/2020, 9:07 AMmanlan
07/01/2020, 5:39 AM