Created
November 27, 2014 01:16
-
-
Save ryoppy/98df53d90111cf701592 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
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