Skip to content

Instantly share code, notes, and snippets.

@ryoppy
Created November 27, 2014 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryoppy/98df53d90111cf701592 to your computer and use it in GitHub Desktop.
Save ryoppy/98df53d90111cf701592 to your computer and use it in GitHub Desktop.
trait Foo[T] {
def bar(list: Seq[T]): Unit
}
object Foo {
def bar[T: Foo](list: Seq[T]): Unit = implicitly[Foo[T]].bar(list)
implicit val FooInt = new Foo[Int] {
def bar(list: Seq[Int]): Unit = println("Int " + list)
}
implicit val FooDouble = new Foo[Double] {
def bar(list: Seq[Double]): Unit = println("Double " + list)
}
implicit val FooFloat = new Foo[Float] {
def bar(list: Seq[Float]): Unit = println("Float " + list)
}
implicit val FooString = new Foo[String] {
def bar(list: Seq[String]): Unit = println("String " + list)
}
}
Foo.bar(Seq(1))
Foo.bar(Seq(1d))
Foo.bar(Seq(1f))
Foo.bar(Seq("1"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment