-
-
Save drstevens/4438371 to your computer and use it in GitHub Desktop.
This demonstrates some of the ways to combine scalaz6 Validaitons. It is the result of answers to question http://stackoverflow.com/questions/13961940/chaining-scalaz-validation-functions-function1a-validatione-b. See answers for more, including combining functions using Kliesi in scalaz6 and scalaz7.
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
def allDigits: (String) => ValidationNEL[String, String] | |
def maxSizeOfTen: (String) => ValidationNEL[String, String] | |
def toInt: (String) => ValidationNEL[String, Int] | |
val validInt: String => ValidationNEL[String, Int] = s => | |
for { | |
validStr <- (allDigits(s) |@| maxSizeOfTen(s))((_,x) => x) | |
i <- toInt(validStr) | |
} yield(i) | |
val validInt: String => ValidationNEL[String, Int] = s => | |
for { | |
_ <- (allDigits(s) <|*|> maxSizeOfTen(s)) | |
i <- toInt(s) | |
} yield(i) | |
//or | |
val validInt: String => ValidationNEL[String, Int] = s => | |
for { | |
validStr <- (allDigits(s) *> maxSizeOfTen(s)) | |
i <- toInt(validStr) | |
} yield(i) | |
//or | |
val validInt: String => ValidationNEL[String, Int] = s => | |
for { | |
validStr <- (allDigits(s) <* maxSizeOfTen(s)) | |
i <- toInt(validStr) | |
} yield(i) | |
//or | |
val validInt: String => ValidationNEL[String, Int] = s => | |
(allDigits(s) *> maxSizeOfTen(s)) flatMap toInt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment