func sample(testList []struct{}, testMap map[int64]struct{}) {
for i, test := range testList {
// some if conditions to get the matched key
testList[i] = testMap[key]
}
}
Run Code Online (Sandbox Code Playgroud)
map 和 slice 的值是相同的类型。我将使用一些匹配的地图值来替换切片中的值。