Validation: implicit scalaz.Bind not found

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 ?
                        ^
+4
source share
1 answer

Validation does not have a binding defined for it.

Scalaz 7.1.0-M5 (M6 ) Validation.flatMap , flatMap scalaz.syntax.bind._, Scalaz._ import. . commit https://github.com/scalaz/scalaz/commit/2727b2451eba2aa159f3fbb62bf92790ac99dc7a. import scalaz.Validation.FlatMap._ , ,

import scalaz.Validation
import scalaz.syntax.validation._

- Validation, , , . . scalaz.\/.

scalaz 7.0.5. Validation.flatMap 7.0.6, . (Validation for) .

, gona , Validation.flatMap . flatMap - , for. flatMap , . . . https://groups.google.com/forum/#!topic/scalaz/Wnkdyhebo2w.

TL;DR - . Validation.flatMap Apply, Validation.

scalaz.\/ (a.k.a. disjunction), - for. , Validation over \/, Validation, \/.

+6

Source: https://habr.com/ru/post/1533334/


All Articles