Last active
October 10, 2019 11:11
-
-
Save jcavat/8a47cdf4f70b097160db536898ea541a to your computer and use it in GitHub Desktop.
Type class method with multiple args
This file contains hidden or 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 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