在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
方法?
\/
答案 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]]