-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
I have a few common use cases that I'm finding hard to deal with. The most obvious one is I want to process lines of a file. It's all fine except that I don't know how to ensure the file is closed once the stream is finished. If I pass Stream objects around I have no way to ensure that. Intuitively, what I want is a syntax like this:
def foo() {
def r = new File("test.txt").newReader()
return new Stream({ f.readLine() })
.filter { blah }
.map { bloop }
.end { r.close() }
}
Then a client of this function can call:
foo().map { fizzle }.until { blag }
And the key point is, the "end { }" closure is guaranteed to be called when the stream terminates, regardless of whether it's because the file was exhausted or whether it's because someone downstream imposed an "until".
Is there a way to handle this right now, or is there a possibility to add such an "end" function?
Metadata
Metadata
Assignees
Labels
No labels