I think I understand what sequence is. I am wondering why it does not work with List[ValidationNel]
. For instance:
The sequence
works fine with List[Option]]
scala> val os = List(1.some, 2.some)
os: List[Option[Int]] = List(Some(1), Some(2))
scala> os.sequence
res10: Option[List[Int]] = Some(List(1, 2))
... but does not work with List[ValidationNel]
scala> val vs: List[ValidationNel[String, Int]] = List(Success(1), Success(2))
vs: List[scalaz.ValidationNel[String,Int]] = List(Success(1), Success(2))
scala> vs.sequence
<console>:15: error: could not find implicit value for parameter ev:scalaz.Leibniz.===[scalaz.ValidationNel[String,Int],G[B]]
... however sequenceU
does work with List[ValidationNel]
scala> vs.sequenceU
res14: scalaz.Validation[scalaz.NonEmptyList[String],List[Int]] = Success(List(1, 2))
My questions are: Why does not sequence
work with List[ValidationNel]
? Why does sequenceU
work with it ?
.sequenceU uses the Unapply technique to derive the correct types, where as for .sequence you need to manually provide the types for it.
To make things a bit more annoying, the first type argument of sequence needs a type parameter that takes one type parameter not two like ValidationNel. So you either type lambda it, or do a local type definition.
Try
or