Kroppeb
12/17/2019, 5:41 AMKroppeb
12/17/2019, 5:44 AMsplit() so I decided to convert to an actual string which took quite some time to get right.
output.toList().joinToString(separator = "") { it.toChar().toString() }.split("\n").map{it.map{it}}Rostyslav
12/17/2019, 7:30 AMoutput.map { it.toChar()}.joinToString("").split("\n").map { it.toList() }Edgars
12/17/2019, 9:04 AMJoris PZ
12/17/2019, 12:19 PM.lines() instead of .split("\n") :
.map { it.toChar() }.toList().joinToString("").lines()Kroppeb
12/17/2019, 12:23 PMsplitLines or somethingJakub Gwóźdź
12/17/2019, 2:56 PMChannel s for I/O, so I added a Flow for it and transform it like this:
@Suppress("BlockingMethodInNonBlockingContext")
private fun Flow<Char>.fullLines(): Flow<String> = flow {
val builder = StringBuilder()
collect {
when (it) {
'\n' -> emit(builder.toString()).also { builder.clear() }
else -> builder.append(it)
}
}
}
this approach has some flaws (e.g. just forgets last line without any \n at the end) but is good enough for day17 🙂Joris PZ
12/17/2019, 3:46 PMlaunch {
while (!stdout.isClosedForReceive) {
stdout.receive().also { print(if (it < 255) it.toChar() else "Part 2: $it") }
}
}