feat: add FilterMap

This commit is contained in:
dudaodong committed 2023-02-24 10:55:27 +08:00
1 parent f7aaa1ed2a
commit 5767aad303
3 files changed
+54

No files matched your search

+19
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"math"
"reflect"
"strconv"
)
func ExampleContain() {
@@ -367,6 +368,24 @@ func ExampleMap() {
// [2 3 4]
}
func ExampleFilterMap() {
nums := []int{1, 2, 3, 4, 5}
getEvenNumStr := func(i, num int) (string, bool) {
if num%2 == 0 {
return strconv.FormatInt(int64(num), 10), true
}
return "", false
}
result := FilterMap(nums, getEvenNumStr)
fmt.Printf("%#v", result)
// Output:
// []string{"2", "4"}
}
func ExampleReduce() {
nums := []int{1, 2, 3}