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

refactor: interface{} -> any

This commit is contained in:
dudaodong
2022-03-16 18:41:40 +08:00
parent af480efa8c
commit c939b26cb8
34 changed files with 194 additions and 195 deletions

View File

@@ -61,7 +61,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -113,7 +113,7 @@ func main() {
type peopleAgeComparator struct{}
// Compare implements github.com/duke-git/lancet/lancetconstraints/constraints.go/Comparator
func (pc *peopleAgeComparator) Compare(v1 interface{}, v2 interface{}) int {
func (pc *peopleAgeComparator) Compare(v1 any, v2 any) int {
p1, _ := v1.(people)
p2, _ := v2.(people)
@@ -171,7 +171,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -216,7 +216,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -261,7 +261,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -306,7 +306,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -351,7 +351,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -395,7 +395,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -440,7 +440,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -486,7 +486,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -533,7 +533,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)

View File

@@ -61,7 +61,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -113,7 +113,7 @@ func main() {
type peopleAgeComparator struct{}
// Compare implements github.com/duke-git/lancet/lancetconstraints/constraints.go/Comparator
func (pc *peopleAgeComparator) Compare(v1 interface{}, v2 interface{}) int {
func (pc *peopleAgeComparator) Compare(v1 any, v2 any) int {
p1, _ := v1.(people)
p2, _ := v2.(people)
@@ -171,7 +171,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -216,7 +216,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -261,7 +261,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -306,7 +306,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -351,7 +351,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -395,7 +395,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -440,7 +440,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -486,7 +486,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)
@@ -533,7 +533,7 @@ import (
func main() {
type intComparator struct{}
func (c *intComparator) Compare(v1 interface{}, v2 interface{}) int {
func (c *intComparator) Compare(v1 any, v2 any) int {
val1, _ := v1.(int)
val2, _ := v2.(int)

View File

@@ -136,7 +136,7 @@ func main() {
<b>Signature:</b>
```go
func ToBytes(data interface{}) ([]byte, error)
func ToBytes(data any) ([]byte, error)
```
<b>Example:</b>
@@ -199,7 +199,7 @@ func main() {
<b>Signature:</b>
```go
func ToFloat(value interface{}) (float64, error)
func ToFloat(value any) (float64, error)
```
<b>Example:</b>
@@ -232,7 +232,7 @@ func main() {
<b>Signature:</b>
```go
func ToInt(value interface{}) (int64, error)
func ToInt(value any) (int64, error)
```
<b>Example:</b>
@@ -265,7 +265,7 @@ func main() {
<b>Signature:</b>
```go
func ToJson(value interface{}) (string, error)
func ToJson(value any) (string, error)
```
<b>Example:</b>
@@ -293,7 +293,7 @@ func main() {
<b>Signature:</b>
```go
func ToString(value interface{}) string
func ToString(value any) string
```
<b>Example:</b>
@@ -321,7 +321,7 @@ func main() {
<b>Signature:</b>
```go
func StructToMap(value interface{}) (map[string]interface{}, error)
func StructToMap(value any) (map[string]any, error)
```
<b>Example:</b>

View File

@@ -138,7 +138,7 @@ func main() {
<b>函数签名:</b>
```go
func ToBytes(data interface{}) ([]byte, error)
func ToBytes(data any) ([]byte, error)
```
<b>列子:</b>
@@ -201,7 +201,7 @@ func main() {
<b>函数签名:</b>
```go
func ToFloat(value interface{}) (float64, error)
func ToFloat(value any) (float64, error)
```
<b>列子:</b>
@@ -234,7 +234,7 @@ func main() {
<b>函数签名:</b>
```go
func ToInt(value interface{}) (int64, error)
func ToInt(value any) (int64, error)
```
<b>例子:</b>
@@ -267,7 +267,7 @@ func main() {
<b>函数签名:</b>
```go
func ToJson(value interface{}) (string, error)
func ToJson(value any) (string, error)
```
<b>列子:</b>
@@ -295,7 +295,7 @@ func main() {
<b>函数签名:</b>
```go
func ToString(value interface{}) string
func ToString(value any) string
```
<b>例子:</b>
@@ -323,7 +323,7 @@ func main() {
<b>函数签名:</b>
```go
func StructToMap(value interface{}) (map[string]interface{}, error)
func StructToMap(value any) (map[string]any, error)
```
<b>列子:</b>

View File

@@ -155,7 +155,7 @@ func main() {
<b>Signature:</b>
```go
func MiMeType(file interface{}) string
func MiMeType(file any) string
```
<b>Example:</b>

View File

@@ -155,7 +155,7 @@ func main() {
<b>函数签名:</b>
```go
func MiMeType(file interface{}) string
func MiMeType(file any) string
```
<b>例子:</b>

View File

@@ -34,7 +34,7 @@ Param should be number or numberic string.</p>
<b>Signature:</b>
```go
func Comma(v interface{}, symbol string) string
func Comma(v any, symbol string) string
```
<b>Example:</b>

View File

@@ -33,7 +33,7 @@ import (
<b>函数签名:</b>
```go
func Comma(v interface{}, symbol string) string
func Comma(v any, symbol string) string
```
<b>例子:</b>

View File

@@ -40,7 +40,7 @@ import (
<b>Signature:</b>
```go
func After(n int, fn interface{}) func(args ...interface{}) []reflect.Value
func After(n int, fn any) func(args ...any) []reflect.Value
```
<b>Example:</b>
@@ -59,7 +59,7 @@ func main() {
return i
})
type cb func(args ...interface{}) []reflect.Value
type cb func(args ...any) []reflect.Value
print := func(i int, s string, fn cb) {
fmt.Printf("arr[%d] is %s \n", i, s)
fn(i)
@@ -87,7 +87,7 @@ func main() {
<b>Signature:</b>
```go
func Before(n int, fn interface{}) func(args ...interface{}) []reflect.Value
func Before(n int, fn any) func(args ...any) []reflect.Value
```
<b>Example:</b>
@@ -109,7 +109,7 @@ func main() {
})
var res []int64
type cb func(args ...interface{}) []reflect.Value
type cb func(args ...any) []reflect.Value
appendStr := func(i int, s string, fn cb) {
v := fn(i)
res = append(res, v[0].Int())
@@ -133,8 +133,8 @@ func main() {
<b>Signature:</b>
```go
type Fn func(...interface{}) interface{}
func (f Fn) Curry(i interface{}) func(...interface{}) interface{}
type Fn func(...any) any
func (f Fn) Curry(i any) func(...any) any
```
<b>Example:</b>
@@ -150,7 +150,7 @@ func main() {
add := func(a, b int) int {
return a + b
}
var addCurry function.Fn = func(values ...interface{}) interface{} {
var addCurry function.Fn = func(values ...any) any {
return add(values[0].(int), values[1].(int))
}
add1 := addCurry.Curry(1)
@@ -168,7 +168,7 @@ func main() {
<b>Signature:</b>
```go
func Compose(fnList ...func(...interface{}) interface{}) func(...interface{}) interface{}
func Compose(fnList ...func(...any) any) func(...any) any
```
<b>Example:</b>
@@ -181,10 +181,10 @@ import (
)
func main() {
add1 := func(v ...interface{}) interface{} {
add1 := func(v ...any) any {
return v[0].(int) + 1
}
add2 := func(v ...interface{}) interface{} {
add2 := func(v ...any) any {
return v[0].(int) + 2
}
@@ -246,7 +246,7 @@ func main() {
<b>Signature:</b>
```go
func Delay(delay time.Duration, fn interface{}, args ...interface{})
func Delay(delay time.Duration, fn any, args ...any)
```
<b>Example:</b>
@@ -275,7 +275,7 @@ func main() {
<b>Signature:</b>
```go
func Schedule(d time.Duration, fn interface{}, args ...interface{}) chan bool
func Schedule(d time.Duration, fn any, args ...any) chan bool
```
<b>Example:</b>

View File

@@ -40,7 +40,7 @@ import (
<b>函数签名:</b>
```go
func After(n int, fn interface{}) func(args ...interface{}) []reflect.Value
func After(n int, fn any) func(args ...any) []reflect.Value
```
<b>例子:</b>
@@ -59,7 +59,7 @@ func main() {
return i
})
type cb func(args ...interface{}) []reflect.Value
type cb func(args ...any) []reflect.Value
print := func(i int, s string, fn cb) {
fmt.Printf("arr[%d] is %s \n", i, s)
fn(i)
@@ -87,7 +87,7 @@ func main() {
<b>函数签名:</b>
```go
func Before(n int, fn interface{}) func(args ...interface{}) []reflect.Value
func Before(n int, fn any) func(args ...any) []reflect.Value
```
<b>例子:</b>
@@ -109,7 +109,7 @@ func main() {
})
var res []int64
type cb func(args ...interface{}) []reflect.Value
type cb func(args ...any) []reflect.Value
appendStr := func(i int, s string, fn cb) {
v := fn(i)
res = append(res, v[0].Int())
@@ -133,8 +133,8 @@ func main() {
<b>函数签名:</b>
```go
type Fn func(...interface{}) interface{}
func (f Fn) Curry(i interface{}) func(...interface{}) interface{}
type Fn func(...any) any
func (f Fn) Curry(i any) func(...any) any
```
<b>例子:</b>
@@ -150,7 +150,7 @@ func main() {
add := func(a, b int) int {
return a + b
}
var addCurry function.Fn = func(values ...interface{}) interface{} {
var addCurry function.Fn = func(values ...any) any {
return add(values[0].(int), values[1].(int))
}
add1 := addCurry.Curry(1)
@@ -168,7 +168,7 @@ func main() {
<b>函数签名:</b>
```go
func Compose(fnList ...func(...interface{}) interface{}) func(...interface{}) interface{}
func Compose(fnList ...func(...any) any) func(...any) any
```
<b>例子:</b>
@@ -181,10 +181,10 @@ import (
)
func main() {
add1 := func(v ...interface{}) interface{} {
add1 := func(v ...any) any {
return v[0].(int) + 1
}
add2 := func(v ...interface{}) interface{} {
add2 := func(v ...any) any {
return v[0].(int) + 2
}
@@ -246,7 +246,7 @@ func main() {
<b>函数签名:</b>
```go
func Delay(delay time.Duration, fn interface{}, args ...interface{})
func Delay(delay time.Duration, fn any, args ...any)
```
<b>例子:</b>
@@ -275,7 +275,7 @@ func main() {
<b>函数签名:</b>
```go
func Schedule(d time.Duration, fn interface{}, args ...interface{}) chan bool
func Schedule(d time.Duration, fn any, args ...any) chan bool
```
<b>例子:</b>

View File

@@ -46,7 +46,7 @@ import (
<b>Signature:</b>
```go
func ConvertMapToQueryString(param map[string]interface{}) string
func ConvertMapToQueryString(param map[string]any) string
```
<b>Example:</b>
@@ -59,7 +59,7 @@ import (
)
func main() {
var m = map[string]interface{}{
var m = map[string]any{
"c": 3,
"a": 1,
"b": 2,
@@ -237,10 +237,10 @@ func main() {
```go
// params[0] is header which type should be http.Header or map[string]string,
// params[1] is query param which type should be url.Values or map[string]interface{},
// params[1] is query param which type should be url.Values or map[string]any,
// params[2] is post body which type should be []byte.
// params[3] is http client which type should be http.Client.
func HttpGet(url string, params ...interface{}) (*http.Response, error)
func HttpGet(url string, params ...any) (*http.Response, error)
```
<b>Example:</b>
@@ -279,10 +279,10 @@ func main() {
```go
// params[0] is header which type should be http.Header or map[string]string,
// params[1] is query param which type should be url.Values or map[string]interface{},
// params[1] is query param which type should be url.Values or map[string]any,
// params[2] is post body which type should be []byte.
// params[3] is http client which type should be http.Client.
func HttpPost(url string, params ...interface{}) (*http.Response, error)
func HttpPost(url string, params ...any) (*http.Response, error)
```
<b>Example:</b>
@@ -328,10 +328,10 @@ func main() {
```go
// params[0] is header which type should be http.Header or map[string]string,
// params[1] is query param which type should be url.Values or map[string]interface{},
// params[1] is query param which type should be url.Values or map[string]any,
// params[2] is post body which type should be []byte.
// params[3] is http client which type should be http.Client.
func HttpPut(url string, params ...interface{}) (*http.Response, error)
func HttpPut(url string, params ...any) (*http.Response, error)
```
<b>Example:</b>
@@ -378,10 +378,10 @@ func main() {
```go
// params[0] is header which type should be http.Header or map[string]string,
// params[1] is query param which type should be url.Values or map[string]interface{},
// params[1] is query param which type should be url.Values or map[string]any,
// params[2] is post body which type should be []byte.
// params[3] is http client which type should be http.Client.
func HttpDelete(url string, params ...interface{}) (*http.Response, error)
func HttpDelete(url string, params ...any) (*http.Response, error)
```
<b>Example:</b>
@@ -417,10 +417,10 @@ func main() {
```go
// params[0] is header which type should be http.Header or map[string]string,
// params[1] is query param which type should be url.Values or map[string]interface{},
// params[1] is query param which type should be url.Values or map[string]any,
// params[2] is post body which type should be []byte.
// params[3] is http client which type should be http.Client.
func HttpPatch(url string, params ...interface{}) (*http.Response, error)
func HttpPatch(url string, params ...any) (*http.Response, error)
```
<b>Example:</b>
@@ -466,7 +466,7 @@ func main() {
<b>Signature:</b>
```go
func ParseHttpResponse(resp *http.Response, obj interface{}) error
func ParseHttpResponse(resp *http.Response, obj any) error
```
<b>Example:</b>

View File

@@ -45,7 +45,7 @@ import (
<b>函数签名:</b>
```go
func ConvertMapToQueryString(param map[string]interface{}) string
func ConvertMapToQueryString(param map[string]any) string
```
<b>例子:</b>
@@ -58,7 +58,7 @@ import (
)
func main() {
var m = map[string]interface{}{
var m = map[string]any{
"c": 3,
"a": 1,
"b": 2,
@@ -235,10 +235,10 @@ func main() {
```go
// params[0] http请求header类型必须是http.Header或者map[string]string
// params[1] http查询字符串类型必须是url.Values或者map[string]interface{}
// params[1] http查询字符串类型必须是url.Values或者map[string]any
// params[2] post请求体类型必须是[]byte
// params[3] http client类型必须是http.Client
func HttpGet(url string, params ...interface{}) (*http.Response, error)
func HttpGet(url string, params ...any) (*http.Response, error)
```
<b>例子:</b>
@@ -277,10 +277,10 @@ func main() {
```go
// params[0] http请求header类型必须是http.Header或者map[string]string
// params[1] http查询字符串类型必须是url.Values或者map[string]interface{}
// params[1] http查询字符串类型必须是url.Values或者map[string]any
// params[2] post请求体类型必须是[]byte
// params[3] http client类型必须是http.Client
func HttpPost(url string, params ...interface{}) (*http.Response, error)
func HttpPost(url string, params ...any) (*http.Response, error)
```
<b>例子:</b>
@@ -326,10 +326,10 @@ func main() {
```go
// params[0] http请求header类型必须是http.Header或者map[string]string
// params[1] http查询字符串类型必须是url.Values或者map[string]interface{}
// params[1] http查询字符串类型必须是url.Values或者map[string]any
// params[2] post请求体类型必须是[]byte
// params[3] http client类型必须是http.Client
func HttpPut(url string, params ...interface{}) (*http.Response, error)
func HttpPut(url string, params ...any) (*http.Response, error)
```
<b>Example:</b>
@@ -376,10 +376,10 @@ func main() {
```go
// params[0] http请求header类型必须是http.Header或者map[string]string
// params[1] http查询字符串类型必须是url.Values或者map[string]interface{}
// params[1] http查询字符串类型必须是url.Values或者map[string]any
// params[2] post请求体类型必须是[]byte
// params[3] http client类型必须是http.Client
func HttpDelete(url string, params ...interface{}) (*http.Response, error)
func HttpDelete(url string, params ...any) (*http.Response, error)
```
<b>例子:</b>
@@ -415,10 +415,10 @@ func main() {
```go
// params[0] http请求header类型必须是http.Header或者map[string]string
// params[1] http查询字符串类型必须是url.Values或者map[string]interface{}
// params[1] http查询字符串类型必须是url.Values或者map[string]any
// params[2] post请求体类型必须是[]byte
// params[3] http client类型必须是http.Client
func HttpPatch(url string, params ...interface{}) (*http.Response, error)
func HttpPatch(url string, params ...any) (*http.Response, error)
```
<b>例子:</b>
@@ -464,7 +464,7 @@ func main() {
<b>函数签名:</b>
```go
func ParseHttpResponse(resp *http.Response, obj interface{}) error
func ParseHttpResponse(resp *http.Response, obj any) error
```
<b>例子:</b>

View File

@@ -126,7 +126,7 @@ import (
func main() {
arr := []string{"a", "b", "c", "d", "e"}
res := slice.Chunk(InterfaceSlice(arr), 3)
fmt.Println(res) //[][]interface{}{{"a", "b", "c"}, {"d", "e"}}
fmt.Println(res) //[][]any{{"a", "b", "c"}, {"d", "e"}}
}
```
@@ -483,7 +483,7 @@ func main() {
<b>Signature:</b>
```go
func FlattenDeep(slice interface{}) interface{}
func FlattenDeep(slice any) any
```
<b>Example:</b>
@@ -570,7 +570,7 @@ func main() {
<b>Signature:</b>
```go
func IntSlice(slice interface{}) []int
func IntSlice(slice any) []int
```
<b>Example:</b>
@@ -581,7 +581,7 @@ import (
)
func main() {
var nums = []interface{}{1, 2, 3}
var nums = []any{1, 2, 3}
res := slice.IntSlice(nums)
fmt.Println(res) //[]int{1, 2, 3}
}
@@ -596,7 +596,7 @@ func main() {
<b>Signature:</b>
```go
func InterfaceSlice(slice interface{}) []interface{}
func InterfaceSlice(slice any) []any
```
<b>Example:</b>
@@ -609,7 +609,7 @@ import (
func main() {
var nums = []int{}{1, 2, 3}
res := slice.InterfaceSlice(nums)
fmt.Println(res) //[]interface{}{1, 2, 3}
fmt.Println(res) //[]any{1, 2, 3}
}
```
@@ -650,7 +650,7 @@ func main() {
<b>Signature:</b>
```go
func InsertAt[T any](slice []T, index int, value interface{}) []T
func InsertAt[T any](slice []T, index int, value any) []T
```
<b>Example:</b>
@@ -788,7 +788,7 @@ func main() {
<b>Signature:</b>
```go
func SortByField(slice interface{}, field string, sortType ...string) error
func SortByField(slice any, field string, sortType ...string) error
```
<b>Example:</b>
@@ -860,7 +860,7 @@ func main() {
<b>Signature:</b>
```go
func StringSlice(slice interface{}) []string
func StringSlice(slice any) []string
```
<b>Example:</b>
@@ -871,7 +871,7 @@ import (
)
func main() {
var s = []interface{}{"a", "b", "c"}
var s = []any{"a", "b", "c"}
res := slice.StringSlice(s)
fmt.Println(res) //[]string{"a", "b", "c"}
}

View File

@@ -126,7 +126,7 @@ import (
func main() {
arr := []string{"a", "b", "c", "d", "e"}
res := slice.Chunk(InterfaceSlice(arr), 3)
fmt.Println(res) //[][]interface{}{{"a", "b", "c"}, {"d", "e"}}
fmt.Println(res) //[][]any{{"a", "b", "c"}, {"d", "e"}}
}
```
@@ -360,7 +360,7 @@ func main() {
### <span id="Every">Every</span>
<p>如果切片中的所有值都通过谓词函数则返回true。 函数签名应该是func(index int, value interface{}) bool</p>
<p>如果切片中的所有值都通过谓词函数则返回true。 函数签名应该是func(index int, value any) bool</p>
<b>函数签名:</b>
@@ -390,7 +390,7 @@ func main() {
### <span id="Filter">Filter</span>
<p>返回与函数匹配的所有元素。 函数签名应该是 func(index int, value interface{}) bool</p>
<p>返回与函数匹配的所有元素。 函数签名应该是 func(index int, value any) bool</p>
<b>函数签名:</b>
@@ -485,7 +485,7 @@ func main() {
<b>函数签名:</b>
```go
func FlattenDeep(slice interface{}) interface{}
func FlattenDeep(slice any) any
```
<b>例子:</b>
@@ -572,7 +572,7 @@ func main() {
<b>函数签名:</b>
```go
func IntSlice(slice interface{}) []int
func IntSlice(slice any) []int
```
<b>例子:</b>
@@ -583,7 +583,7 @@ import (
)
func main() {
var nums = []interface{}{1, 2, 3}
var nums = []any{1, 2, 3}
res := slice.IntSlice(nums)
fmt.Println(res) //[]int{1, 2, 3}
}
@@ -598,7 +598,7 @@ func main() {
<b>函数签名:</b>
```go
func InterfaceSlice(slice interface{}) []interface{}
func InterfaceSlice(slice any) []any
```
<b>例子:</b>
@@ -611,7 +611,7 @@ import (
func main() {
var nums = []int{}{1, 2, 3}
res := slice.InterfaceSlice(nums)
fmt.Println(res) //[]interface{}{1, 2, 3}
fmt.Println(res) //[]any{1, 2, 3}
}
```
@@ -652,7 +652,7 @@ func main() {
<b>函数签名:</b>
```go
func InsertAt[T any](slice []T, index int, value interface{}) []T
func InsertAt[T any](slice []T, index int, value any) []T
```
<b>例子:</b>
@@ -790,7 +790,7 @@ func main() {
<b>函数签名:</b>
```go
func SortByField(slice interface{}, field string, sortType ...string) error
func SortByField(slice any, field string, sortType ...string) error
```
<b>例子:</b>
@@ -862,7 +862,7 @@ func main() {
<b>函数签名:</b>
```go
func StringSlice(slice interface{}) []string
func StringSlice(slice any) []string
```
<b>例子:</b>
@@ -873,7 +873,7 @@ import (
)
func main() {
var s = []interface{}{"a", "b", "c"}
var s = []any{"a", "b", "c"}
res := slice.StringSlice(s)
fmt.Println(res) //[]string{"a", "b", "c"}
}

View File

@@ -237,7 +237,7 @@ func main() {
<b>Signature:</b>
```go
func IsString(v interface{}) bool
func IsString(v any) bool
```
<b>Example:</b>

View File

@@ -238,7 +238,7 @@ func main() {
<b>函数签名:</b>
```go
func IsString(v interface{}) bool
func IsString(v any) bool
```
<b>例子:</b>