0

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

object CurriedTest {

  def main(args: Array[String]): Unit = {
    fun("one")("two")("three")
    (fun2)("three")
    val lst = List ("x", "y", "z")
    lst.foreach(fun2) 
    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?

duplode
  • 33,731
  • 7
  • 79
  • 150
DarqMoth
  • 603
  • 1
  • 13
  • 31

1 Answers1

4

Remove comma from this line

lst.foreach(fun("one"),("two") _) 
Sergii Lagutin
  • 10,561
  • 1
  • 34
  • 43