上QQ阅读APP看书,第一时间看更新
Map Example
Here's an example of mapping a collection using the alediaferia/go-collections package:
names := []interface{}{
"Alice",
"Bob",
"Cindy",
}
collection := collections.NewFromSlice(names)
collection = collection.Map(func(v interface{}) interface{} {
return strings.Join([]string{"Hey", v.(string)}, " ")
})
println(collection) // or the use of fmt.Println(collection)
The output is as follows:
Hey Alice
Hey Bob
Hey Cindy