github.com/database64128/shadowsocks-go@v1.10.2-0.20240315062903-143a773533f1/maphelper/maphelper.go (about)

     1  package maphelper
     2  
     3  // Keys returns the keys of the map m.
     4  // The keys will be in an indeterminate order.
     5  func Keys[M ~map[K]V, K comparable, V any](m M) []K {
     6  	r := make([]K, 0, len(m))
     7  	for k := range m {
     8  		r = append(r, k)
     9  	}
    10  	return r
    11  }
    12  
    13  // Values returns the values of the map m.
    14  // The values will be in an indeterminate order.
    15  func Values[M ~map[K]V, K comparable, V any](m M) []V {
    16  	r := make([]V, 0, len(m))
    17  	for _, v := range m {
    18  		r = append(r, v)
    19  	}
    20  	return r
    21  }