Reputation:
See the following function definition with implicit return type:
scala> def getIn(nodes:NodeSeq, path:String) = {
| nodes map {node => node \ path}
| }
getIn: (nodes: scala.xml.NodeSeq, path: String)scala.collection.immutable.Seq[scala.xml.NodeSeq]
However, if the function is defined with the same return type explicitly, an error occurs:
scala> def getIn(nodes:NodeSeq, path:String) = Seq[NodeSeq] {
| nodes map {node => node \ path}
| }
<console>:9: error: type mismatch;
found : scala.collection.immutable.Seq[scala.xml.NodeSeq]
required: scala.xml.NodeSeq
nodes map {node => node \ path}
I cannot wrap my head around why the error occurs. Please help me.
Upvotes: 0
Views: 90
Reputation: 272207
In your second case, you're not defining the return type correctly. You need
def getIn(nodes:NodeSeq, path:String) : Seq[NodeSeq] = { ...
Upvotes: 4