I have seen this solution work on the past, so I'm unsure what I'm doing wrong. Consider the answer of How does type class resolution in scala work?
out of it I did this code:
import org.specs2.mutable.Specification
case class OptionFinder[A](isOption: Boolean)
object OptionFinder extends LowerPriority {
implicit def hitOption[A]: OptionFinder[Option[A]] = OptionFinder(true)
}
trait LowerPriority {
implicit def notOption[A]: OptionFinder[A] = OptionFinder(false)
}
object OptionFinderSpec extends Specification {
"OptionFinder" should {
"find Options" in {
def myFunction[A](value: A)(implicit optionFinder: OptionFinder[A]): Boolean = {
optionFinder.isOption
}
myFunction(5) must beFalse
myFunction(None) must beTrue
myFunction(Some(5)) must beTrue
}
}
}
On my understanding, all tests should pass. For some reason both myFunction(None) must beTrue
and myFunction(Some(5)) must beTrue
fail
What am I doing wrong?