I was reading dispatch's code, and come across this file, in which, it says:
object Elem extends (Res => scala.xml.Elem) {
def apply(res: Res) =
XML.withSAXParser(factory.newSAXParser).loadString(res.getResponseBody)
...
What does object Elem extends (Res => scala.xml.Elem) mean?
A => B is the syntax used to describe anonymous functions.
The object declaration
object Elem extends (Res => scala.xml.Elem) { /* ... */ }
is shorthand for
object Elem extends Function1[Res, scala.xml.Elem] { /* ... */ }
In natural language: Elem is a function which produces a scala.xml.Elem object from a Res object.
A look at the scaladoc for Function1 shows that Function1 declares an abstract apply method which is used to implement the function's logic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With