DarqMoth DarqMoth - 5 months ago 57
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?


Remove comma from this line

lst.foreach(fun("one"),("two") _)