[英]Scalaz: sequence of disjuntions to the disjunction of sequence
I am trying to transform List[\\/[String, Int]]
to \\/[String, List[Int]]
. 我正在尝试将
List[\\/[String, Int]]
为\\/[String, List[Int]]
。 All solutions that I was able to find point out to the usage of sequenceU
. 我能够找到的所有解决方案都指出了
sequenceU
的用法。 I was not able to return \\/[String, List[Int]]
, since sequenceU returns type GM[List[GA]]
: 我无法返回
\\/[String, List[Int]]
,因为sequenceU返回了GM[List[GA]]
:
def f(x: Int): \/[String, Int] = if (x > 0) x.right[String] else "failure".left[Int]
val result: G.M[List[G.A]] = List(3, 4, 5).map(f).sequenceU
What am I doing wrong with sequenceU
? 我对
sequenceU
怎么了? How it should be used to get \\/[String, List[Int]]
? 应该如何使用它获取
\\/[String, List[Int]]
?
Just remove the type ascription: 只需删除类型说明:
scala> val result = List(3, 4, 5).map(f).sequenceU
result: scalaz.\/[String,List[Int]] = \/-(List(3, 4, 5))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.