Skip to content

Instantly share code, notes, and snippets.

@clayrat
Created February 24, 2015 19:34
Show Gist options
  • Save clayrat/ab96c9063bd464c925bc to your computer and use it in GitHub Desktop.
Save clayrat/ab96c9063bd464c925bc to your computer and use it in GitHub Desktop.
import shapeless._
import shapeless.PolyDefns.~>
import shapeless.HList._
object Test {
object size extends (Id ~> Const[Int]#λ) {
def apply[T](t : T) = 1
}
implicit def sizeString = size.λ[String](s => s.length)
implicit def sizeTuple[T, U](implicit st : size.λ[T], su : size.λ[U]) =
size.λ[(T, U)](t => 1+size(t._1)+size(t._2))
def main(args: Array[String]) {
val alist = 1 :: ("a", 2) :: "aa" :: HNil
println(alist map size toList)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment