I have the following piece of code.I have to confirm whether its the way how it works..Can anyone provide the explanation for this
object Implicits
{
implicit class RichSeq[A](val xs:Seq[A])
{
def mapD[B](function:A => B):Seq[B] = xs.map(function)
}
}
This is something like a abstraction over map that i can use with a sequence. So if I import this Implicits.RichSeq I can use the methods over any Seq[A] as this will convert Seq[A] into a RichSeq[A].
import Implicits.RichSeq._
val xs:Seq[Int] = Seq(22,33)
val output:Seq[Int] = xs.mapD(_+22)
I want to know how this works because when I use mapD on a type Seq[A] it will search for a implicit conversion from Seq[A] to RichSeq[A].Where does it find this implicit conversion as this is a implicit class?
Does it expand implicit class to something like:
implicit def RichSeq[A](val xs:Seq[A]) = new RichSeq(xs)
I think it might be doing this stuff inside.Does ne1 know about this?