title: Duplicates in Golang code
body: <p>How to get rid off duplicates from this code? </p>
  
  <p>I thought about code generation with <em>go generate</em>, but I think will get the same result. On other side I thought 'bout use interface, but don't know how to apply(I know how to use them, but not in that particular case).</p>
  
  <pre><code>package main
  
  import "fmt"
  
  type First struct {
      X int
      Y float64
  }
  
  type Second struct {
      I float64
      J int
  }
  
  func ListFirsts(db map[string]map[int]interface{}) []First {
      ans := []First{}
      for _, v := range db["Firsts"] {
          ans = append(ans, v.(First))
      }
      return ans
  }
  
  func ListSeconds(db map[string]map[int]interface{}) []Second {
      ans := []Second{}
      for _, v := range db["Seconds"] {
          ans = append(ans, v.(Second))
      }
      return ans
  }
  
  func main() {
      db := map[string]map[int]interface{}{
          "Firsts": {
              1: First{1, 2},
              2: First{2, 3},
          },
          "Seconds": {
              1: Second{11.2, 2},
              2: Second{2, 3},
          },
      }
  
      fmt.Println(ListFirsts(db))
      fmt.Println(ListSeconds(db))
  }
  </code></pre>