tateisu
11/24/2020, 2:22 AMgildor
11/24/2020, 4:19 AMtateisu
11/24/2020, 9:44 AM// parser with recursive call
suspend fun simpleParser(ch: ReceiveChannel<Char>, nest: Int = 0) {
while (true) {
when (val a = ch.receiveOrNull()) {
null, ']' -> break
'[' -> simpleParser(ch, nest + 1)
else -> println("$nest $a")
}
}
}
runBlocking {
simpleParser(
flowOf('a', '[', 'b', ']', 'c')
.produceIn(this)
)
}
flow.collectIterator{ it -> while(it.hasNext() ) it.read() }
gildor
11/24/2020, 2:17 PMtateisu
11/24/2020, 5:04 PM