Skip to content

Instantly share code, notes, and snippets.

@Lakret
Created August 1, 2013 20:33
Show Gist options
  • Save Lakret/6135015 to your computer and use it in GitHub Desktop.
Save Lakret/6135015 to your computer and use it in GitHub Desktop.
Check, whether implicit conversion exists. (Source of idea: http://stackoverflow.com/questions/5717868/test-if-implicit-conversion-is-available)
scala> def implicitExists[A](implicit i: A = null) = i != null
implicitExists: [A](implicit i: A)Boolean
scala> trait Constructable[+A] { def get: A }
defined trait Constructable
scala> case class Page()
defined class Page
scala> implicitExists[Constructable[Page]]
res0: Boolean = false
scala> implicit val pageToConstr = new Constructable[Page] { def get = Page() }
pageToConstr: Constructable[Page] = $anon$1@2e7e34db
scala> implicitExists[Constructable[Page]]
res1: Boolean = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment