title: anonymous struct and empty struct
body: <p><a href="http://play.golang.org/p/vhaKi5uVmm" rel="noreferrer">http://play.golang.org/p/vhaKi5uVmm</a></p>
  
  <pre><code>package main
  
  import "fmt"
  
  var battle = make(chan string)
  
  func warrior(name string, done chan struct{}) {
      select {
      case opponent := &lt;-battle:
          fmt.Printf("%s beat %s\n", name, opponent)
      case battle &lt;- name:
          // I lost :-(
      }
      done &lt;- struct{}{}
  }
  
  func main() {
      done := make(chan struct{})
      langs := []string{"Go", "C", "C++", "Java", "Perl", "Python"}
      for _, l := range langs { go warrior(l, done) }
      for _ = range langs { &lt;-done }
  }
  </code></pre>
  
  <p><strong>[1st Question]</strong></p>
  
  <pre><code> done &lt;- struct{}{}
  </code></pre>
  
  <p>How and Why do we need this weird-looking struct? Is it empty struct or anonymous struct? I googled it but couldn't find the right answer or documentation to explain about this.</p>
  
  <p>The original source is from Andrew Gerrand's talk
  <a href="http://nf.wh3rd.net/10things/#10" rel="noreferrer">http://nf.wh3rd.net/10things/#10</a></p>
  
  <p>Here</p>
  
  <pre><code> make(chan struct{})
  </code></pre>
  
  <p>done is a channel of type struct{}</p>
  
  <p>So I tried with </p>
  
  <pre><code> done &lt;- struct{}
  </code></pre>
  
  <p>But it is not working. Why do I need an extra brackets for this line?</p>
  
  <pre><code> done &lt;- struct{}{}
  </code></pre>
  
  <hr>
  
  <p><strong>[2nd Question]</strong></p>
  
  <pre><code> for _ = range langs { &lt;-done }
  </code></pre>
  
  <p>Why do I need this line? I know that this line is necessary because without this line, no output. But Why and what does this line do? And what makes it necessary in this code? I know that <code>&lt;-done</code> is to receive values from the channel done and discard the received values. But why do I need to do this?</p>