Skip to content

Instantly share code, notes, and snippets.

@machisuji
Created March 5, 2014 09:47
Show Gist options
  • Save machisuji/9364255 to your computer and use it in GitHub Desktop.
Save machisuji/9364255 to your computer and use it in GitHub Desktop.
// 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.")
}
@joescii
Copy link

joescii commented Mar 7, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment