Trouble with goroutines in a for loop
<p>I am trying to solve this problem on <a href="http://exercism.io/exercises/go/parallel-letter-frequency/readme" rel="noreferrer">Exercism</a>:</p>

<blockquote>
  <p>Write a program that counts the frequency of letters in texts using parallel computation.</p>
</blockquote>

<p>Basically, I have a <code>FreqMap</code> type:</p>

<pre><code>type FreqMap map[rune]int
</code></pre>

<p>And a <code>Frequency</code> function:</p>

<pre><code>func Frequency(s string) FreqMap {
    m := make(FreqMap)
    for _, v := range s {
        m[v]++
    }
    return m
}
</code></pre>

<p>Exercism provides an example implementing a concurrent version using recursion, but I would like to implement my own version using a <code>for</code>  loop. I came up with the following solution, which does not work:</p>

<pre><code>func ConcurrentFrequency(l []string) FreqMap {
    c := make(chan FreqMap)
    for i := 0; i &lt; len(l); i++ {
        go func(i int) {
            c &lt;- Frequency(l[i])
        }(i)
    }
    return &lt;- c
}
</code></pre>

<p>This seems to return after only 1 iteration, <code>c</code> seems to contain the result of only 1 goroutine; I get the same result if I add a <code>sync.WaitGroup</code>.</p>

<p>Could you please explain what I am missing here?</p>

<p>Thank you in advance for your help!</p>