Last active
August 29, 2015 14:23
-
-
Save tixxit/1324897c8f6217041faa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scalaVersion := "2.11.6" | |
libraryDependencies ++= Seq( | |
"com.chuusai" %% "shapeless" % "2.2.2" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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