Created
November 24, 2014 02:32
-
-
Save wheaties/ba74b29ad8c83633dc95 to your computer and use it in GitHub Desktop.
Pre-Post Conditionals on Functions
This file contains 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
//This even reasonably useable? | |
implicit class AddPost[T, R](f: T => R){ | |
def withPostCondition(pred: R => Boolean) = {x: T => | |
val out = f(x) | |
if(pred(out)) out else throw new MatchException("Did not satisfy post condition") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment