Question

I have some code which uses either applicative and monad syntax. The code looks like this:

  import scalaz._
  import scalaz.syntax.applicative._
  import scalaz.syntax.std.boolean._
  import scalaz.syntax.traverse._
  //import scalaz.syntax.monad._

  def getPackage[P](implicit pkg: NpmPackage[P]): ValidationNel[String, P] = {
    val installPackage = (pkg: String) => install(pkg).??!!

    lazy val getPackage = pkg.commands.traverseU {
      (c: String) => (binDir |@| binaryForPackage[P](c)) {
        (a: File,b:File) => c -> a / pkg.packageName / b.toString
      }
    } map (_.toMap) map (pkg.newPackage)

    hasPackage(pkg.packageName) ?
      getPackage |
      (installPackage(pkg.packageName) flatMap (_ => getPackage))
  }

That code compiles without problems, just when i want to replace the flatMap method with >>= method importing scalaz.syntax.monad._ i got the following error:

 [error] value |@| is not a member of scalaz.ValidationNel[String,sbt.File]
 [error]      (c: String) => (binDir |@| binaryForPackage[P](c)) {

I suppose that i'm doing something wrong in the imports, but i cant understand why importing monad syntax brokes the |@| operator and how to let both syntax work together, any solution?

I'm using scalaz 7.1.0-M2.

Was it helpful?

Solution

monad syntax includes applicative syntax by extending ToApplicativeOps, so you can remove applicative._ import and just leave monad._ import. On the other hand if you need just applicative apply functionality and bind, you can import just them:

import scalaz.syntax.apply._
import scalaz.syntax.bind._
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top