feat: add FlatMap

This commit is contained in:
dudaodong committed 2023-02-24 11:14:59 +08:00
1 parent 5767aad303
commit f3801bcd8f
3 files changed
+39

No files matched your search

+14
View File
@@ -386,6 +386,20 @@ func ExampleFilterMap() {
// []string{"2", "4"}
}
func ExampleFlatMap() {
nums := []int{1, 2, 3, 4}
result := FlatMap(nums, func(i int, num int) []string {
s := "hi-" + strconv.FormatInt(int64(num), 10)
return []string{s}
})
fmt.Printf("%#v", result)
// Output:
// []string{"hi-1", "hi-2", "hi-3", "hi-4"}
}
func ExampleReduce() {
nums := []int{1, 2, 3}