简体   繁体   English

scalaz.syntax.std.OptionOps.cata在scalaz中做什么?

[英]What does scalaz.syntax.std.OptionOps.cata do in scalaz?

Here is a description about cata function from scalaz. 这是来自scalaz的关于cata功能的描述 But what is a purpose og using this function? 但是使用此功能的目的是什么? By the way is there a scaladoc for scalaz with description, not only code. 顺便说一下,这里有一个scaladoc,用于scalaz以及说明,而不仅仅是代码。

It's the same as fold on scala.Option : it lets you map both the has-a-value branch and the empty branch into a single result value. 它与在scala.Option fold相同:它使您可以将has-a-value分支和empty分支映射到单个结果值。 Anywhere you might see 随处可见

Option(x) match {
  case Some(y) => f(y)
  case None => y0
}

you can use fold on Option or cata on scalaz' variant instead. 您可以使用foldOptioncata上scalaz”变种来代替。

(Note: for this particular case, pattern matching is typically more efficient, but not always more convenient.) (注意:对于这种特殊情况,模式匹配通常更有效,但并不总是更方便。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM