Created
February 24, 2015 19:34
-
-
Save clayrat/ab96c9063bd464c925bc to your computer and use it in GitHub Desktop.
This file contains 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
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