Alexjok
01/17/2019, 2:10 PMsergey.trufanov
01/17/2019, 3:30 PMнарезать его на партиции по
?Alexjok
01/17/2019, 3:42 PMtapac
01/19/2019, 10:09 PMfun <T> List<T>.partition(nextPartition: (T) -> Boolean) : List<List<T>> {
val result = mutableListOf<MutableList<T>>()
var current = mutableListOf<T>()
val last = size - 1
result += current
forEachIndexed { index, el ->
current.add(el)
if (nextPartition(el) && index != last) {
current = mutableListOf()
result += current
}
}
return result
}
fun main(args: Array<String>) {
val testList = mutableListOf<Test>()
createList(testList)
testList.partition { it.endPart == 1 }.forEach {
println(it.joinToString(" ") { it.value })
}
}
Alexjok
01/21/2019, 7:51 AMtapac
01/21/2019, 7:52 AM