How to convert functions raising exceptions to functions returning Either?
Suppose I have a few functions that raise exceptions. I am wrapping them to return Either[Throwable, <function return type>] . (Let's assume I need Either rather than Try ). def fooWrapper(arg1: FooArg1, arg2: FooArg2) = try Right(foo(arg1, arg2)) catch { case NonFatal(e) => Left(e) } def barWrapper(arg1: BarArg1, arg2: BarArg2, a3: BarArg3) = try Right(bar(arg1, arg2, artg3)) catch { case NonFatal(e) => Left(e) } ... Now I would like to write a generic wrapper to get rid of the bolierpllate code. What would you suggest ? I would write something of the form like this: def wrap[Value](f: =>