I have an implementation of scalaz Validation, it looks like this is implicitly scalaz.Bind is not in scope, so it does not work for expression. Here is the code:
import scalaz._
import Scalaz._
case class User(name: String, knowScala: Boolean, age: Int)
object PublicValidationSpec extends BasicValidation {
def validate(user: User): Validation[String, String] = {
for {
b <- checkAge(user)
c <- checkName(user)
} yield s"Congrats, ${c.name}"
}
}
trait BasicValidation {
def checkName(user: User): Validation[String, User] = {
if(user.name == "") "must have a name".fail else user.success
}
def checkAge(user: User): Validation[String, User] = {
if(user.age < 3) "must be a valid age".fail else user.success
}
}
the exception is
Error:(14, 25) Implicit not found: scalaz.Unapply[scalaz.Bind,
scalaz.Validation[String,scalaz.validation.User]]. Unable to unapply type
`scalaz.Validation[String,scalaz.validation.User]` into a type constructor of
kind `M[_]` that is classified by the type class `scalaz.Bind`. Check that the
type class is defined by compiling `implicitly[scalaz.Bind[type constructor]]` and
review the implicits in object Unapply, which only cover common type 'shapes.'
b <- checkAge(user)
Did i miss some implicit imports here ?
^
source
share