DarqMoth DarqMoth - 1 year ago 95
Scala Question

Scala: curried function in foreach?

I am trying to use curried function when iterating collection with 'foreach' method:

object CurriedTest {

def main(args: Array[String]): Unit = {
val lst = List ("x", "y", "z")
lst.foreach(fun("one"),("two") _)


def fun (a1: String) (a2:String) (a3: String) = {
println("a1: "+a1+" a2: "+a2+" a3: "+a3)

def fun2 = fun("one")("two") _

Why line 'lst.foreach(fun("one"),("two") _) ' does not compile and return:

- too many arguments for method foreach: (f: String => B)Unit

error message?

Answer Source

Remove comma from this line

lst.foreach(fun("one"),("two") _) 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download