Guest User

Untitled

a guest
Nov 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. def wrap[T](code: => T):Either[Exception,T] = try {
  2. Right(code)
  3. } catch {
  4. case e:Exception => Left(e)
  5. }
  6.  
  7. val x = wrap { "foo" }
  8. // x is a Right[Exception,String]("foo")
  9. val y = wrap { throw new RuntimeException("bar") }
  10. // y is a Left[Exception,Nothing](RuntimeException(bar))
Add Comment
Please, Sign In to add comment