title: Reassignment to a val in Scala
body: <p>I am doing a training exercise in Scala and getting this val reassignment error. I don't see where I am reassigning a new value to a val</p>
  
  <pre><code>class personTest
  {
    val alf = Person("Alf", 30, List(EmailAddress("alf.kristian@gmail.com")))
    val fredrik = Person("Fredrik", 33, List(EmailAddress("fredrik@vraalsen.no"), EmailAddress("fvr@knowit.no")))
    val johannes = Person("Johannes", 0, Nil)
  
    val persons = List(alf, fredrik, johannes)
  
     @Test
    def testNameToEmailAddress
    {
      // Create a map from each persons name to their e-mail addresses,
      // filtering out persons without e-mail addresses
      // Hint: First filter list, then use foldLeft to accumulate...
      val emptyMap: Map[String, List[EmailAddress]] = Map()
  
      val nameToEmail = persons.filter(_.emailAddresses.length&gt;0).foldLeft(emptyMap)((b,p)=&gt; b+=p.name-&gt;p.emailAddresses)
  
      assertEquals(Map(alf.name -&gt; alf.emailAddresses, fredrik.name -&gt; fredrik.emailAddresses), nameToEmail)
    }
  
  }
  </code></pre>
  
  <p>and I am getting this error</p>
  
  <pre><code>error: reassignment to val
  val nameToEmail = persons.filter(_.emailAddresses.length&gt;0).foldLeft(emptyMap)((b,p)=&gt; b+=p.name-&gt;p.emailAddresses)
  </code></pre>