title: Single function iterate a map or slice with generics
body: <p>Is there a way using Go's new generics to have a single <code>for</code> in a function be able to iterate over a loop or a slice?</p>
  <p>This is roughly what I'm wanting to do, with a little more logic attached based on keys.</p>
  <pre class="lang-golang prettyprint-override"><code>func iterateContent[K []interface{} | map[string]interface{}](items K) {
      for k, _ := range items {
          fmt.Println(k)
      }
  }
  </code></pre>
  <p>This code though gives me the following error</p>
  <blockquote>
  <p>cannot range over items (variable of type K constrained by []interface{}|map[string]interface{}) (K has no core type)</p>
  </blockquote>
  <hr />
  <p>There are other questions on StackOverflow about how to iterate varying types of slices, but they're fundamentally different than varying between a slice and a map.</p>