In Java’s try-with-resource construct multiple managed resources can be used:
try(final InputStream is = new FileInputStream(file);
final OutputStream os = new FileOutputStream(file)) { ... }
To my knowledge, Scala’s Using
is the closest equivalent to said Java’s try-with-resource construct. If I am not completely wrong and misread the respective Scaladoc, Using
only manages one single resource.
What is the best pattern to handle multiple resources in Scala?
Disclaimer: I half understand that cats-effects has something for this use case, but before I start using libraries I’d like to understand how things are done in vanilla Scala.