Skip to content

Instantly share code, notes, and snippets.

@travisbrown
Created October 14, 2016 21:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save travisbrown/bbd1162b8bc7d2bf39e29fadf55db223 to your computer and use it in GitHub Desktop.
Save travisbrown/bbd1162b8bc7d2bf39e29fadf55db223 to your computer and use it in GitHub Desktop.
class TC[A](val x: String)
object TC {
def getX[A: TC](a: A): String = implicitly[TC[A]].x
implicit def anyTC[A]: TC[A] = new TC[A]("*")
implicit val stringTC: TC[String] = new TC[String]("String")
}
object Example {
val strings = List("a", "b")
val ee1 = strings.map(TC.getX)
val ee2 = strings.map(TC.getX _)
val af1 = strings.map(TC.getX(_))
val af2 = strings.map(s => TC.getX(s))
}
@travisbrown
Copy link
Author

scala> Example.ee1
res0: List[String] = List(*, *)

scala> Example.ee2
res1: List[String] = List(*, *)

scala> Example.af1
res2: List[String] = List(String, String)

scala> Example.af2
res3: List[String] = List(String, String)

@travisbrown
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment