Skip to content

Instantly share code, notes, and snippets.

@mesagie
Last active December 15, 2015 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mesagie/5303585 to your computer and use it in GitHub Desktop.
Save mesagie/5303585 to your computer and use it in GitHub Desktop.
Restricting the scope of implicits
// 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