diesieben07
08/03/2018, 11:50 AMval input = listOf(4, 1, 1, 3, 2, 5, 2)
val output = input.chunkedBy { it % 2 == 0 } // should be: [[4, 1, 1, 3], [2, 5], [2]]
Is there such a thing in the standard library?nfrankel
08/03/2018, 11:53 AMgroupBy()
?
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/group-by.htmldiesieben07
08/03/2018, 11:53 AMgroupBy
returns a Map thoughnfrankel
08/03/2018, 11:56 AMspand
08/03/2018, 11:56 AM.values
or do you absolutely need a List
?diesieben07
08/03/2018, 11:57 AMnfrankel
08/03/2018, 11:59 AMdiesieben07
08/03/2018, 11:59 AMnfrankel
08/03/2018, 12:00 PMchunked()
is based on size...spand
08/03/2018, 12:02 PMfold
is the closest you can getdiesieben07
08/03/2018, 12:02 PMpartition
only checks a boolean conditionrrader
08/03/2018, 1:39 PMval input = listOf(4, 1, 1, 3, 2, 5, 2)
println(input.partition({ it % 2 == 0 }))
diesieben07
08/03/2018, 1:41 PMrrader
08/03/2018, 1:42 PMdiesieben07
08/03/2018, 1:43 PMrrader
08/03/2018, 1:44 PMdiesieben07
08/03/2018, 1:44 PMRichard Green
08/03/2018, 1:51 PMfitzoh
08/03/2018, 2:23 PMtakeWhile
diesieben07
08/03/2018, 2:24 PMWhat if the first n elements (n>0) are not true for the condition?Then they would be in their own group. I want behavior "like String.split".
hho
08/03/2018, 2:31 PMkarelpeeters
08/03/2018, 2:34 PMcondition.invoke(it)
-> condition(it)
diesieben07
08/03/2018, 2:42 PMkarelpeeters
08/03/2018, 2:43 PMdiesieben07
08/03/2018, 2:49 PMhho
08/03/2018, 2:49 PMdiesieben07
08/03/2018, 2:49 PM