Skip to content

Instantly share code, notes, and snippets.

@wheaties
Created November 24, 2014 02:32
Show Gist options
  • Save wheaties/ba74b29ad8c83633dc95 to your computer and use it in GitHub Desktop.
Save wheaties/ba74b29ad8c83633dc95 to your computer and use it in GitHub Desktop.
Pre-Post Conditionals on Functions
//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