News for hackers. Stuff that matters.
Re:The Next Step for Generics by benhoyt on Tuesday June 16, 2020 @10:54PM (#23547209)
I started to write one in the "Go 2 playground", but then realized they had that exact example in the draft design:

   func Keys(type K comparable, V interface{})(m map[K]V) []K {
    r := make([]K, 0, len(m))
    for k := range m {
     r = append(r, k)
    }
    return r
   }
Usage:

   m := map[int]int{1:2, 2:4}
   k := maps.Keys(m)
   // Now k is either []int{1, 2} or []int{2, 1}.

There are no comments on this comment yet.