mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-10-06 07:26:53 +08:00
支持 ExtractKeys 和 ExtractValues 方法 (#92)
This commit is contained in:
17
mapUtil/extract_keys_example_test.go
Normal file
17
mapUtil/extract_keys_example_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package mapUtil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func ExampleExtractKeys() {
|
||||
m := map[string]int{"apple": 5, "banana": 3, "orange": 7}
|
||||
keys := ExtractKeys(m)
|
||||
|
||||
// 对结果排序以确保输出一致(map 迭代顺序随机)
|
||||
sort.Strings(keys)
|
||||
fmt.Println("Keys:", keys)
|
||||
|
||||
// Output: Keys: [apple banana orange]
|
||||
}
|
Reference in New Issue
Block a user