« Return to Thread: concise function literal as foreach argument

concise function literal as foreach argument

by Chris Lewis-8 :: Rate this Message:

Reply to Author | View in Thread

Hello list,

I'm having a strange type resolution error in a function literal.
Given this:

tracks\\"track" foreach { track => println(track\"name" text) }

where tracks is a NodeSeq, I can iterate over each "track" element and
dump its "name" text node. The literal syntax doesn't have a type
declaration, and so I figured this could be further reduced:

tracks\\"track" foreach { println(_\"name" text) }

However the compiler falls over with:

error: missing parameter type for expanded function ((x$1) =>
x$1.$bslash("name").text)
    tracks\\"track" foreach { println(_\"name" text) }

That doesn't make sense, give that a) it knows the type of the
collection (inferred to NodeSeq) and b) the working example merely
names the variable, but doesn't declare its type. Am I missing
something here?

Sincerely,
Chris

 « Return to Thread: concise function literal as foreach argument