Skip to content

Instantly share code, notes, and snippets.

@jcavat
Last active October 10, 2019 11:11
Show Gist options
  • Save jcavat/8a47cdf4f70b097160db536898ea541a to your computer and use it in GitHub Desktop.
Save jcavat/8a47cdf4f70b097160db536898ea541a to your computer and use it in GitHub Desktop.
Type class method with multiple args
trait Testable[T,R] {
def test(t: T, s: String): R
}
object Testable {
def apply[T,R](implicit testable: Testable[T,R]): Testable[T,R] = testable
implicit class Ops[T,R](t: T)(implicit testable: Testable[T,R]) {
def test(s: String): R = Testable[T,R].test(t, s)
}
implicit val stringCan: Testable[String,String] = (s1,s2) => s1 + s2
}
import Testable._
"hello".test(" world") //=> hello world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment