| Newsgroups |
gmane.comp.lang.scala |
| Message-ID |
<[email protected]> |
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.
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.