...
This commit is contained in:
parent
df52a9102d
commit
0a23c4a5a4
2 changed files with 6 additions and 6 deletions
|
@ -30,8 +30,8 @@ func main() {
|
|||
fmt.Println(m)
|
||||
fmt.Println(slicex.MakeMap(
|
||||
s,
|
||||
func(v Struct) string {
|
||||
return v.Name
|
||||
func(s []Struct, i int) string {
|
||||
return s[i].Name
|
||||
},
|
||||
))
|
||||
|
||||
|
|
|
@ -2,14 +2,14 @@ package slicex
|
|||
|
||||
func MakeMap[K comparable, V any](
|
||||
values []V,
|
||||
fn func(V) (K),
|
||||
fn func([]V, int) (K),
|
||||
) map[K] V {
|
||||
var k K
|
||||
|
||||
r := make(map[K] V)
|
||||
for _, v := range values {
|
||||
k = fn(v)
|
||||
r[k] = v
|
||||
for i, _ := range values {
|
||||
k = fn(values, i)
|
||||
r[k] = values[i]
|
||||
}
|
||||
|
||||
return r
|
||||
|
|
Loading…
Reference in a new issue