is there a better way to write this in Kotlin? I'm not trying to solve anything real, just playing around
Copy code
fun File.asSequence(): Sequence<String> {
val reader = this.bufferedReader()
return sequence {
while (true) {
yield(reader.readLine() ?: break)
}
}
}
and is combining scopes frown upon? for example
Copy code
fun File.asSequence2(): Sequence<String> = this.bufferedReader().let {
// now sequence { } allows me to have `it` for the reader and `this` for the sequence
}
(ignore the fact that that first line in particular got really long)