First for a minor point: the type parameter for successNel
is the error type, not the success type, so it needs to be the same across all the arguments to sequence
.
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 a 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 apply the Foo
constructor manually.