-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Introduce Loan object, a Scala implementation of try-with-resources #6347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
There are may other names for this construct. For example: I find that name to be much more descriptive. |
|
We should consider extending the native |
|
@lrytz adding try-with-resource to the core language would be great. The program transformation in https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.20.3 shouldn't be hard to implement in the compiler. That said, I never worried about the allocation of the |
|
I would suggest posting on https://contributors.scala-lang.org to call attention to this PR. We may end up merging some form of this, but it needs community discussion. (Posting on Discourse will reach people who don't watch this repo.) |
The scala library depends on Java classes in many places and ways. The strategy so far has been to cross-compile Scala ports of the Java classes for Scala.is and scala-native. |
|
What do you think about implementation by type class ? |
|
@ocadaruma Closer-pattern would allow the scala implementation to be independent of AutoCloseable. Ofcourse an implementation of a |
|
Heads up: if this is going to make it into 2.13, it will need to be ready to merge by M5 (due Aug 10). |
|
@varming I'm going to close this for inactivity, since we are trying to hard to cut down on the number of open PRs scala/scala. (closing the PR for now doesn't mean anything about its eventual chances of success.) |
|
the action's at #6907 now |
The try-with-resources construction in Java (introduced in Java 7) is too useful to not have a counterpart in the Scala standard library (IMHO). WDYT? Are you up for adding something like Loan?
I also added a method
orValuetoTry. You can see the usefulness of that method in my implementation ofLoan.I wasn't sure how you handle Java classes leaking into the Scala library. Is it permissible to use java.lang.AutoCloseable?