Skip to content

Instantly share code, notes, and snippets.

@erikkaplun
Created October 22, 2014 16:30
Show Gist options
  • Save erikkaplun/8cbd87fe6a6e002274a4 to your computer and use it in GitHub Desktop.
Save erikkaplun/8cbd87fe6a6e002274a4 to your computer and use it in GitHub Desktop.
// libraryDependencies ++= Seq(
// "org.scalaz" %% "scalaz-core" % "7.1.0",
// "com.chuusai" %% "shapeless" % "2.0.0",
// "org.typelevel" %% "shapeless-scalacheck" % "0.3",
// "org.typelevel" %% "shapeless-spire" % "0.3",
// "org.typelevel" %% "shapeless-scalaz" % "0.3"
// )
import shapeless._, contrib.scalaz._, syntax.std.tuple._
import syntax.std.function._, ops.function._
import shapeless.ops.hlist._
import Poly._
type Va[A] = Validation[String, A]
type VaNel[A] = ValidationNel[String, A]
object toValidationNel extends Poly1 {
implicit def apply[T] = at[Va[T]](_.toValidationNel)
}
def validateGen[P <: Product, F, L1 <: HList, L2 <: HList, L3 <: HList, R, Lx, Out <: Product](params: P)(block: F)(
implicit
gen: Generic.Aux[P, L1],
uc1: UnaryTCConstraint[L1, Va],
mp: Mapper.Aux[toValidationNel.type, L1, L2],
seq: Sequencer.Aux[L2, VaNel[L3]],
tup: Tupler.Aux[L3, Out]
// fn: FnToProduct.Aux[F, Out => R]
) = {
sequence(gen.to(params).map(toValidationNel)).map(_.tupled)//.map(block.toProduct)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment