\ /?的等价选项序列和遍历方法是什么?

时间:2016-09-13 12:21:55

标签: scala scalaz

在scalaz 7.2.6上,这有效:

// import scalaz.syntax.traverse._

List(1.some, 2.some, 3.some).sequence
res12: Option[List[Int]] = Some(List(1, 2, 3))

List(1.some, none, 3.some).sequence
res13: Option[List[Int]] = None

def doubleSmall(x: Int) = if (x < 30) (x * 2).some else none
List(1,2,3).traverse(doubleSmall)
res15: Option[List[Int]] = Some(List(2, 4, 6))

以下代码无法编译。对于Option,是否有sequence的{​​{1}}和traverse方法?

\/

1 个答案:

答案 0 :(得分:1)

您正在寻找module fp_check ( input real a, output real c); assign c = a/6; endmodule module tb_fp_check; real a; real c; initial begin a = 2e-309; #5 $display("a=%b, c=%f", a,c); end fp_check fp (.a(a), .c(c)); endmodule sequenceU

traverseU

请注意,第一个示例需要一个类型提示,以便它可以获取正确的隐式scala> List[\/[String, Int]](1.right, 2.right, 3.right).sequenceU res3: scalaz.\/[String,List[Int]] = \/-(List(1, 2, 3)) scala> List(1.right, 2.right, 3.right, "a".left).sequenceU res4: scalaz.\/[String,List[Int]] = -\/(a)

Unapply[Applicative, \/[String, Int]]