Skip to content

Instantly share code, notes, and snippets.

@szoio

szoio/hlist.scala

Created Jun 9, 2020
Embed
What would you like to do?
Shapeless Intro
import shapeless._
val oneHello = 1 :: "hello" :: Nil
val oneHello = 1 :: "hello" :: HNil
final case class User(name: String, age: Int)
val genericUser = Generic[User]
type GenericUserType = genericUser.Repr
val user = User("Stephen", 42)
val userGen = Generic[User].to(user)
val backToUser = Generic[User].from(userGen)
val userLabelledGen = LabelledGeneric[User].to(user)
val backToUser = LabelledGeneric[User].from(userLabelledGen)
val name: "name" = "name"
sealed trait Shape
case class Circle(radius: Int) extends Shape
case class Rectangle(height: Int, width: Int) extends Shape
case object Point extends Shape
val genericShape = Generic[Shape]
val circleGen = genericShape.to(Rectangle(2, 3))
val backToCircle = genericShape.from(circleGen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment