liwei
07/20/2018, 1:47 AMpablisco
07/20/2018, 3:12 AMGrouping
to a Sequence
?pablisco
07/20/2018, 3:13 AMmap.toList()
pablisco
07/20/2018, 3:22 AMgrouping.aggregate { key, sequence, element, _ ->
sequence?.let { it + (key to element) } ?: sequenceOf(key to element)
}
user
07/20/2018, 6:26 AMuser
07/20/2018, 6:35 AMuser
07/20/2018, 6:36 AMGraham Smith
07/20/2018, 9:42 AMuser
07/20/2018, 9:56 AMuser
07/20/2018, 10:02 AMuser
07/20/2018, 10:04 AMPrateek
07/20/2018, 11:58 AMgaspard
07/20/2018, 1:00 PMgaspard
07/20/2018, 1:00 PMkef
07/20/2018, 4:00 PMcategories: Map<Int, Int>
with key being category id, and value being id of a parent. For any given category I want to find full path, till parent id = 0. My current solution is kinda ugly:
var id: Int = categoryId
val path = mutableListOf<Int>()
do {
path.add(id)
id = categories[id]!!
} while (id != 0)
How can I write this better, without yield?Richard Cumberland
07/20/2018, 4:09 PMkef
07/20/2018, 4:29 PMtipsy
07/21/2018, 10:48 AMNikky
07/21/2018, 12:13 PMif else
in a multiline string ?
multiline strings are raw strings, interpolation does not work in there afaikNikky
07/21/2018, 12:15 PMkristofdho
07/21/2018, 12:35 PMNikky
07/21/2018, 2:24 PMfun main(args: Array<String>) {
val line = "aaaaaaaa"
val b = true
println(
"""
${if(b) line else ""}
"""
)
}
tipsy
07/21/2018, 2:30 PMtipsy
07/21/2018, 2:30 PMNikky
07/21/2018, 4:13 PMShawn
07/21/2018, 9:28 PMOptional.filter()
maybe defined as an extension to Any?
that I’m missing? ?.let { if (predicate(it)) it else null }
and I couldn’t help but wonder if there’s a more idiomatic approach?perryprog
07/22/2018, 12:26 AMreplace(input: CharSequence, transform: (MatchResult) -> CharSequence): String
. I’m now realizing though that this doesn’t have the same behavior as findAll. Is there something like findAll, that replaces all occurrences of a regex with the result of a closure? Apologizes if I worded that badly.karelpeeters
07/22/2018, 12:28 AMperryprog
07/22/2018, 12:28 AMperryprog
07/22/2018, 12:31 AM