如何在scalaz中导入===

egg*_*tbr 3 scalaz

我需要从scalaz使用EqualsOps(===),但是导入scalaz.Scalaz._会给我与anorm的get方法的命名冲突。

这是编译错误:

reference to get is ambiguous;
[error] it is imported twice in the same scope by
[error] import scalaz.Scalaz._
[error] and import anorm.SqlParser._
Run Code Online (Sandbox Code Playgroud)

如何将===纳入范围而又不引起与主动脉的冲突?

tri*_*rNZ 5

去掉 import scalaz.Scalaz._

假设您正在比较原始元素,

import scalaz._
import std.anyVal._
import syntax.equal._
Run Code Online (Sandbox Code Playgroud)

如果是别的东西,说弦,更换std.anyVal._,用std.string._

本质上,第一行给你的各种scalaz类型(如果你不希望这样,更换stdscalaz.std,和语法使用scalaz.syntax)。

第2行为您提供了图元的隐式转换。这样一来,您就可以将图元作为Equal,或者实际上与其他scalaz类型类一样对待,(Monoid等)。第3行为您提供了EqualOps此功能,使您可以将===语法与be一起使用Equal

希望能有所帮助