1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-10 07:42:27 +08:00

feat: add FilterMap

This commit is contained in:
dudaodong
2023-02-24 10:55:27 +08:00
parent f7aaa1ed2a
commit 5767aad303
3 changed files with 54 additions and 0 deletions

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}