Manuel Pérez Alcolea
07/26/2020, 2:09 AMfun File.asSequence(): Sequence<String> {
val reader = this.bufferedReader()
return sequence {
while (true) {
yield(reader.readLine() ?: break)
}
}
}
and is combining scopes frown upon? for example
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)tseisel
07/26/2020, 8:28 AMuseLines
extension function from the stdlib: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/java.io.-file/use-lines.html
As for your 2nd question, I see nothing bad in mixing it
and this
as long as it is still obvious which refers to what.