title: Iterating over list with lambda forEach Kotlin
body: <p>I have a list of 30 random numbers that correspond to 1 of 8 colours, and I need to iterate over the 8 colors(or 30 numbers) and find the number of times each colour occurs. I need to do this using lambdas and functional programming, so no traditional for loops. </p>
  
  <pre><code>val iterator = colours.toList().iterator()
  
  iterator.forEach{
  
      println("$it count: " + (numbers
              .map{a -&gt; colours[a]}
              .count{it == ("$it")}))
  }
  </code></pre>
  
  <p>The problem currently is my output for count is just 50, not the specific number of times a colour occurs. </p>
  
  <p>If I do it like this:</p>
  
  <pre><code>println("Red count:" +    (numbers
          .map{a -&gt; colours[a]}
          .count{it ==  ("red")}))
  </code></pre>
  
  <p>it outputs the correct number, but not with the loop.</p>
  
  <p>What it ouputs:</p>
  
  <pre><code>green count: 50 
  
  red count: 50
  </code></pre>
  
  <p>what it should output (for example)</p>
  
  <pre><code>green count:9
  
  red count:3
  </code></pre>
  
  <p>Thanks in advance</p>