I started reading Scala in Action as my first Scala book (I've come to realize this book is way too advanced for beginners, i am struggling mightily).
I need help with the following.
object Combinators {
implicit def kestrel[A](a: A) = new {
def tap(sideEffect: A => Unit): A = {
sideEffect(a)
a
}
}
}
case class Person(firstName: String, lastName: String)
case class Mailer(mailAddress: String) {
def mail(body: String) = {
println("send mail here...")
}
}
object Main {
import Combinators._
def main(args: Array[String]): Unit = {
Person("Nilanjan", "Raychaudhuri").tap(p => {
println("First name " + p.firstName)
Mailer("some address").mail("new person joined " + p)
}).lastName
}
}
My questions are as follows:
1) How does Person automatically get access to "tap"?
2) What does the implicit keyword do here? (am guessing this might answer q #1)
3) Any other book suggestions for a Java guy trying to learn Scala. (I've got about 10 years of Java experience, if that helps).
Thanks in advance.