title: Scala - Example of Fold Operation on a HashMap ** not foldLeft
body: <p>I am interested in using Scala because it seems like a good way to parallelize operations. I need to design a machine learning algorithm that makes use of vector multiplication (as do many). I know how to do the algorithm, but what I want to make is a sparse vector implementation from HashMaps. Pretty much all vectors are stored as HashMaps[Int, Double] where the index of a given double in a vector is the integer that is the key.</p>
  
  <p>Using a Pythonish psuedocode,
  &lt;7, 6, 5, 4>  ==> {1:7, 2:6, 3:5, 4:4}</p>
  
  <p>I want to define a dot product function using either fold, reduce, map ... etc., but I DO NOT want to use the foldLeft, reduceLeft ... because I would like this to be potentially parallizable because my vectors can get up to 6000+ dimensions and, for dot products, order does not matter.</p>
  
  <p>I have read MANY examples of foldLeft and reduceLeft, but I have yet to find out how to use HashMap.fold or HashMap.reduce.</p>
  
  <p>I understand functional programming to a decent extent, but I don't understand the error messages in Scala. Here is a template of what I want more or less.</p>
  
  <pre><code>object NGramAnalysis {
    def main(args: Array[String]) {
      val mapped = HashMap(1-&gt;1.2, 5-&gt;2.4)
      println(mapped.fold( .... What goes here ... )
    }
  }
  </code></pre>
  
  <p><strong>Conclusion</strong>
  I want a solid example of using HashMap.fold <strong>NOT foldLeft</strong> and the same for HashMap.reduce</p>
  
  <p>Thank you in advance. I have been struggling for a while.</p>