Skip to content

Instantly share code, notes, and snippets.

@tixxit
Last active August 29, 2015 14:23
Show Gist options
  • Save tixxit/1324897c8f6217041faa to your computer and use it in GitHub Desktop.
Save tixxit/1324897c8f6217041faa to your computer and use it in GitHub Desktop.
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.2.2"
)
package net.tixxit.examples.eugene
import shapeless._
import shapeless.ops.hlist._
final case class LongType(x: Long)
final case class DoubleType(x: Double)
final case class StringType(x: String)
object convert extends Poly1 {
implicit def convLong = at[LongType](_.x)
implicit def convDouble = at[DoubleType](_.x)
implicit def convString = at[StringType](_.x)
}
object Main extends App {
val xs: LongType :: DoubleType :: StringType :: HNil =
LongType(1) :: DoubleType(2D) :: StringType("3") :: HNil
val ys: Long :: Double :: String :: HNil = xs.map(convert)
println(xs)
println(ys)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment