Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def wrap[T](code: => T):Either[Exception,T] = try {
- Right(code)
- } catch {
- case e:Exception => Left(e)
- }
- val x = wrap { "foo" }
- // x is a Right[Exception,String]("foo")
- val y = wrap { throw new RuntimeException("bar") }
- // y is a Left[Exception,Nothing](RuntimeException(bar))
Add Comment
Please, Sign In to add comment