I am trying to transform List[\\/[String, Int]]
to \\/[String, List[Int]]
. All solutions that I was able to find point out to the usage of sequenceU
. I was not able to return \\/[String, List[Int]]
, since sequenceU returns type 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
? How it should be used to get \\/[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))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.