https://kotlinlang.org logo
#getting-started
Title
# getting-started
l

Lewis Diamond

02/15/2021, 4:07 AM
Is there a built-in way to read stdin as a stream? Something like Node's
process.stdin
?
n

nanodeath

02/15/2021, 4:32 AM
well, there's System.
in
the global
readLine()
might also be useful
l

Lewis Diamond

02/15/2021, 4:38 AM
I did this with
readLine()
but that's kinda bad:
Copy code
fun stdin(): Flow<String?> = flow { // flow builder
    while (true) {
        var x = readLine();
        emit(x);
    }
}
testing out System.
in
Need to look at that syntax though
n

nanodeath

02/15/2021, 4:43 AM
I don't know about flows, but you at least want
readLine() ?: break
...and no semicolons 😛
2 Views