First for the lowest point: the type parameter for successNel
is the type of error, not the type of success, so it should be the same for all sequence
arguments.
So, we can write the following (assuming our errors are strings):
import shapeless._, contrib.scalaz._ import scalaz._, syntax.validation._ case class Foo(i: Int, s: String) implicit val fooIso = Iso.hlist(Foo.apply _, Foo.unapply _) val valHList = sequence(1.successNel[String] :: "2".successNel[String] :: HNil)
This gives us an Int :: String :: HNil
inside the validation. Now we can use our isomorphism:
scala> valHList.map(fooIso.from) res0: scalaz.Validation[scalaz.NonEmptyList[String],Foo] = Success(Foo(1,2))
No need to deconstruct the list and use the Foo
constructor manually.
source share