-
Couldn't load subscription status.
- Fork 1.1k
How to use Using.Manager with Scala 3 given #18318
-
In Scala 2, it's common to write
import scala.util.Using Using.Manager { implicit use => runProgram() } def runProgram()(implicit use: Using.Manager): Unit = println("hello world")
How can we convert this to Scala 3?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments 4 replies
-
Can you provide a complete piece of code that compiles in Scala 2?
Beta Was this translation helpful? Give feedback.
All reactions
-
Sorry, edited :)
Beta Was this translation helpful? Give feedback.
All reactions
-
inline def managed[T](inline op: Using.Manager ?=> T): Try[T] = Using.Manager(op(using _)) managed: runProgram()
Beta Was this translation helpful? Give feedback.
All reactions
-
That's great, although it would be ideal if users could write something like
Using.Manager { given use =>
runProgram()
}
Directly. Or maybe def managed could be added to the StdLib eventually.
Beta Was this translation helpful? Give feedback.
All reactions
-
Using.Manager { case given Using.Manager => runProgram() }
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2
-
@som-snytt very nice
Beta Was this translation helpful? Give feedback.