I am reading text from a java BufferedReader
like this:
Stream.continually(reader.readLine).takeWhile {
case null => reader.close; false
You can get the .whenDone
behaviour by appending another Stream
.
This makes the code a bit more expressive and could also be used in other cases. It is something but I guess far from perfect.
def closeStream: Stream[Nothing] = {
reader.close
Stream.Empty
}
Stream.continually(reader.readLine).takeWhile(_ != null) #::: closeStream