I am testing out some code shown below that basically defines multiple implicit val
s taking a string as input and converting it to corresponding types.
The problem I have is that the conversions like toLong
, toDouble
and toInt
become unresolved for some reason.
class Parse[T](val f: String => T) extends (String => T) {
def apply(s: String): T = f(s)
}
object Parse {
def apply[T](f: String => T) = new Parse[T](f)
implicit val parseLong: Parse[Long] = Parse[Long](s => s.toLong)
implicit val parseDouble: Parse[Double] = Parse[Double](s => s.toDouble)
implicit val parseInt: Parse[Int] = Parse[Int](s => s.toInt)
}
What is wrong with this code?