Skip to content

Instantly share code, notes, and snippets.

@rjsvaljean
Created September 24, 2016 21:21
Show Gist options
  • Select an option

  • Save rjsvaljean/ba6873dccd2181c1a9a8227ce6b0e7a4 to your computer and use it in GitHub Desktop.

Select an option

Save rjsvaljean/ba6873dccd2181c1a9a8227ce6b0e7a4 to your computer and use it in GitHub Desktop.
For a given F[_], a type level check that the HList L looks like F[A] :: F[B] :: F[C] :: HNil and fails to compile when it looks like F[A] :: SomeOtherType :: HNil
sealed trait IsDataType[F[_], L <: HList]
object IsDataType {
implicit def hnil[F[_]]: IsDataType[F, HNil] = new IsDataType[F, HNil] {}
implicit def rest[F[_], H, T <: HList : ({type l[a] = IsDataType[F, a]})#l]: IsDataType[F, ::[F[H], T]] =
new IsDataType[F, F[H] :: T] {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment