Managing imports in Scalaz7

前端 未结 1 1607
庸人自扰
庸人自扰 2020-12-17 17:44

I am using scalaz7 in a project and sometimes I run into issues with imports. The simplest way get started is

import scalaz._
import Scalaz._
相关标签:
1条回答
  • 2020-12-17 18:01

    This blog post explains the package structure and imports a la carte in scalaz7 in detail: http://eed3si9n.com/learning-scalaz-day13

    For your specific examples, for 3.failure[String] you'd need:

    import scalaz.syntax.validation._
    

    Validation already has a method ap:

    scala> "hello".successNel[Int] ap ((s: String) => "x"+s).successNel[Int]
    res1: scalaz.Validation[scalaz.NonEmptyList[Int],java.lang.String] = Success(xhello)
    

    To get the <*> operator, you need this import:

    import scalaz.syntax.applicative._
    

    Then you can do:

    "hello".successNel[Int] <*> ((s: String) => "x"+s).successNel[Int]
    
    0 讨论(0)
提交回复
热议问题