fwaris
fwaris

Reputation: 1

type mismatch error involving nested parentheses

type mismatch

found   : ((A, (Long, Array[String], Int))) => A
required: (A, (Long, Array[String], Int)) => A

I don't understand this error I am trying to fold over a sequence where A is the state type. Why has it 'found' a nested tuple where I have provided something like:

xs.foldLeft(zeroSt) {case (st,(a,b,c)) => st}

Upvotes: 0

Views: 77

Answers (1)

Mario Galic
Mario Galic

Reputation: 48410

There is a syntax error where accumulator parameter of foldLeft is missing

xs.foldLeft(zeroSt) { case (acc, (st, (a, b, c))) => // accumulate in acc }
                             ^
                             |
                        this was missing

In other words, B was specified incorrectly in the signature of foldLeft

def foldLeft[B](z: B)(op: (B, A) => B): B
                           ^
                           |
                        this was incorrect

As a side note, I use the following mnemonic to remember where the accumulator fits:

  • with foldLeft the accumulator is the "left" element of the tuple
  • with foldRight the accumulator is the "right" element of the tuple

Upvotes: 2

Related Questions