How do I write this kind of pattern in Kotlin? ```...
# getting-started
f
How do I write this kind of pattern in Kotlin?
Copy code
while ((line = inp.readLine()) != null) {
            result.append(line)
        }
d
funrep: Very idiomatic way:
Copy code
generateSequence { inp.readLine() }.forEach { line -> result.append(line) }
f
nice that looks good, thanks!
d
Or, with references:
generateSequence(inp::readLine).forEach(result::append)
(Doesn't work)
v
or
File("").forEachLine { ... }
👍 5
or
File("").readLines()
👍 1
This whole
result.append(line)
looks very unclean, should be
map
at least