scala - 不理解 scalaz 中的行为

标签 scala scalaz

这里是一位 ScalaZ 新手提出的问题。 我不太明白如何:

1.some

或与析取相关:

"Success!".right 

工作。 我无法找到任何允许上述行为的隐式转换。 我知道如何使用它们,但我对它们的实现感兴趣。 谢谢。

最佳答案

包含方法some的类是OptionIdOps

final class OptionIdOps[A](self: A) {
  def some: Option[A] = Some(self)
}

如果查看定义内部,您将看到特征定义中可用于任何类型 AOptionIdOps 的附加隐式:

trait ToOptionIdOps {
  implicit def ToOptionIdOps[A](a: A) = new OptionIdOps(a)
}

事实上,编译器会:

val someOfInt = new OptionIdOps(1).some

关于scala - 不理解 scalaz 中的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42782922/

相关文章:

scala - 覆盖 Predef 的隐式转换

java - 如何在 Play 2.5.x (Scala) 中禁用弱密码和客户端重新协商

java - 如何使用 java/scala 将图像数据插入 mySql mediumtext 字段?

scala - 在 Scala 中正确编码这种存在类型?

haskell - 合理的 Comonad 实现

Scala:在一次调用中将相同的函数应用于 2 个列表

scala - 类别到底是什么?

Scalaz 的 Unapply : why doesn't traverseU work with State? 为什么必须存在 traverseS?

scala - 忽略自定义任务和范围中的 SBT 工件?