[英]Behavior in scalaz not understood
A question from a ScalaZ neophite here. 这里是来自ScalaZ新星的一个问题。 I don't quite understand how the:
我不太了解:
1.some
or the disjunction related: 或与析取有关的内容:
"Success!".right
work. 工作。 I am not able to find any implicit conversions that will allow the behavior above.
我找不到任何允许上述行为的隐式转换。 I know how to use them but I am interested in their implementation.
我知道如何使用它们,但是我对它们的实现感兴趣。 Thank you.
谢谢。
The class containing the method some
is OptionIdOps
包含
some
方法的类是OptionIdOps
final class OptionIdOps[A](self: A) {
def some: Option[A] = Some(self)
}
If you look inside the definition, you'll see an additional implicit available for any type A
to OptionIdOps
inside a trait definition: 如果在定义内部查看,您将看到特征定义内
OptionIdOps
任何类型A
可用的附加隐式:
trait ToOptionIdOps {
implicit def ToOptionIdOps[A](a: A) = new OptionIdOps(a)
}
So de-facto, the compiler does: 实际上,编译器会执行以下操作:
val someOfInt = new OptionIdOps(1).some
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.