Created
January 21, 2014 21:18
-
-
Save manjuraj/8548582 to your computer and use it in GitHub Desktop.
TryHarder - Try with finally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.Try | |
implicit class TryHarder[T](t:Try[T]) { | |
def harder(f: => Unit) = {f; t} | |
} | |
Try(1/0).harder(println("finally")) // prints 'finally' | |
Try(try { ??? } finally { 1 / 0 }).harder(println("finally finally")) // prints 'finally finally' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment