Created
March 5, 2014 09:47
-
-
Save machisuji/9364255 to your computer and use it in GitHub Desktop.
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
// improper use of a pattern match IMO | |
val negative = Constraint[Int] { | |
case i if i < 0 => Valid | |
_ => Invalid("Must be a negative number.") | |
} | |
// why not use if-else ? | |
val negative2 = Constraint[Int](i => | |
if (i < 0) Valid | |
else Invalid("Must be a negative number.")) | |
// or in what ever style you prefer | |
val negative3 = Constraint[Int] { i => | |
if (i < 0) | |
Valid | |
else | |
Invalid("Must be a negative number.") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I agree that the use of pattern matching isn't necessary. Although, it's possible that using a partial function gives other advantages in this example. Not sure TBH