Skip to content

Instantly share code, notes, and snippets.

@ant8e
Created November 7, 2014 13:34
Show Gist options
  • Save ant8e/587dad89659aeabbd213 to your computer and use it in GitHub Desktop.
Save ant8e/587dad89659aeabbd213 to your computer and use it in GitHub Desktop.
import scala.reflect.runtime.universe._
object O {
def foo[A: TypeTag](xs: List[A]): String = xs match {
case c: List[String] if typeOf[A] <:< typeOf[String] => c.mkString(" ")
case c: List[Double] if typeOf[A] <:< typeOf[Double] => c.map(_.toString + "d").mkString (" ")
case _ => "Error"
}
}
O.foo(List("hello","world"))
O.foo(List(1.0, 2.0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment