Skip to content

Instantly share code, notes, and snippets.

@fogfish
Created May 4, 2018 10:44
Show Gist options
  • Save fogfish/aef674ce09af47aef384b567c450a3fd to your computer and use it in GitHub Desktop.
Save fogfish/aef674ce09af47aef384b567c450a3fd to your computer and use it in GitHub Desktop.
Use Poly1 to Map HList
import shapeless._
object size extends Poly1 {
implicit def default[T] = at[T](t => (t, 1))
implicit def caseInt = at[Int](x => (x, x))
implicit def caseString = at[String](s => (s, s.length))
}
val hl = "one" :: 2 :: "three" :: HNil
hl.map(size)
hl.map(size).toList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment