title: Scala error "value map is not a member of Double"
body: <p>Explanation: I accepted <a href="https://stackoverflow.com/users/1149944/gzm0">gzm0's</a> answer because it rocked!</p>
  
  <p>@Eduardo did come in with a comment suggesting:</p>
  
  <pre><code>(for(i &lt;- 10..20; j=runTest(i)) yield i -&gt; j).toMap
  </code></pre>
  
  <p>which also lets me run build, he just never posted an answer and @gzm0 answer was conceptually AWESOME so I accepted it.</p>
  
  <p><a href="https://stackoverflow.com/questions/34983987/scala-constructor-stopwatch-cannot-be-accessed-in-class-main">Once I get this other issue figured out relating to "can't call constructor"</a> I will be able to test these out by actually running the program LOL </p>
  
  <p>Question: I have an error in this expression, specifically how to fix it but more generally what am I missing about FP or Scala to make this mistake?</p>
  
  <pre><code>timingsMap = for (i &lt;- powersList; j &lt;- runTest(i)) yield i -&gt; j
  </code></pre>
  
  <p>I am Writing my first Gradle/Scala project for a Analysis of Algorithms assignment. Scala is not part of the assignment so I am not using a homework tag. Except for my work with Spark in Java, I am brand new to Functional Programming I am sure that's the problem. </p>
  
  <p>Here's a snippet, <a href="https://github.com/jimlohse/RedBlackTree4150/blob/master/src/main/scala/Main.scala" rel="nofollow noreferrer">the full .scala file is on GitHub</a>, is that OK or I will post the full program here if I get flailed :)</p>
  
  <pre><code>val powersList = List(10 to 20)
  
  // create a map to keep track of power of two and resulting timings
  var timingsMap: Map[Integer, Double] = Map()
  
  // call the runTest function once for each power of two we want, from powersList,
  // assign timingsMap the power of 2 value and results of runTest for that tree size
  timingsMap = for (i &lt;- powersList; j &lt;- runTest(i)) yield i -&gt; j
  </code></pre>
  
  <p>The error is:
      /home/jim/workspace/Scala/RedBlackTree4150/src/main/scala/Main.scala:36: value map is not a member of Double
        timingsMap = for (i &lt;- powersList; j &lt;- runTest(i)) yield i -> j</p>
  
  <p>What I <strong>think</strong> I am doing in that <code>timingsMap = ...</code> line is get all the elements of <code>powersList</code> mapped onto <code>i</code> for each iteration of the loop, and the return value for <code>runTest(i)</code> mapped onto <code>j</code> for each iteration, and then taking all those pairs and putting them into <code>timingsMap</code>. Is it the way I am trying to use <code>i</code> in the loop to <code>call runTest(i)</code> that causes the problem?</p>
  
  <p>runTest looks like this:</p>
  
  <pre><code>def runTest(powerOfTwo: Range): Double = {
  
      // create the tree here
      var tree = new TreeMap[Int, Double]
  
      // we only care to create a tree with integer keys, not what the value is
      for (x &lt;- powerOfTwo) {
        // set next entry in map to key, random number
        tree += (x -&gt; math.random)
      }
  
      stopWatchInst.start()
  
      // now go through and look up all the values in the tree,
      for (x &lt;- powerOfTwo) {
        // get the value, don't take the time/overhead to store it in a var, as we don't need it
        tree.get(x)
      }
  
      // stop watch check time report and return time
      stopWatchInst.stop()
      val totalTime = stopWatchInst.elapsed(TimeUnit.MILLISECONDS)
      loggerInst.info("run for 2 to the power of " + powerOfTwo + " took " + totalTime + " ms")
      return totalTime
    }
  </code></pre>
  
  <hr>
  
  <p>Note: I've had a suggestions to change the <code>j &lt;-</code> to <code>=</code> in <code>j &lt;-</code> in this line: timingsMap = for (i &lt;- powersList; j &lt;- runTest(i)) yield i -> j</p>
  
  <p>Another suggestion didn't like using yield at all and suggested replacing with (10 to 20).map...</p>
  
  <p><strong>The strange part is the existing code does not show an error in the IntelliJ editor, only breaks when I run it. The suggestions all give type mismatch errors in the IDE. I am really trying to figure out conceptually</strong> what I am doing wrong, thanks for any help! (and of course I need to get it to work!)</p>
  
  <hr>
  
  <p>After trying gzm0 answer I am getting down the same road ... my code as presented doesn't show any type mismatches until I use <code>gradle run</code> ... whereas when I make the suggested changes it starts to give me errors right in the IDE ... but keep em coming! Here's the latest error based on gzm0s answer:</p>
  
  <pre><code>/home/jim/workspace/Scala/RedBlackTree4150/src/main/scala/Main.scala:37: type mismatch;
   found   : List[(scala.collection.immutable.Range.Inclusive, Double)]
   required: Map[Integer,Double]
    timingsMap = for (i &lt;- powersList) yield i -&gt; runTest(i)
  </code></pre>