Last active
December 15, 2015 18:28
-
-
Save mesagie/5303585 to your computer and use it in GitHub Desktop.
Restricting the scope of implicits
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
// a function with non-ambiguous type signature | |
def justDoIt(implicit p0: Char, p1: String, p2: Int) = p0 + p1 * p2 | |
// restrict the scope of implicits | |
{ | |
implicit val x = 3 | |
implicit val c = 'a' | |
implicit val s = "abc" | |
justDoIt // returns aabcabcabc | |
} | |
justDoIt // compilation error: could not find implicit value for parameter p2: Int |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment