mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-15 18:22:27 +08:00
docs: add doc for function Equal and EqualWithFunc
This commit is contained in:
@@ -30,6 +30,8 @@ import (
|
|||||||
- [DifferenceBy](#DifferenceBy)
|
- [DifferenceBy](#DifferenceBy)
|
||||||
- [DeleteByIndex](#DeleteByIndex)
|
- [DeleteByIndex](#DeleteByIndex)
|
||||||
- [Drop](#Drop)
|
- [Drop](#Drop)
|
||||||
|
- [Equal](#Equal)
|
||||||
|
- [EqualWith](#EqualWith)
|
||||||
- [Every](#Every)
|
- [Every](#Every)
|
||||||
- [Filter](#Filter)
|
- [Filter](#Filter)
|
||||||
- [Find](#Find)
|
- [Find](#Find)
|
||||||
@@ -332,6 +334,68 @@ func main() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="Equal">Equal</span>
|
||||||
|
<p>Check if two slices are equal: the same length and all elements' order and value are equal.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func Equal(slice1, slice2 interface{}) bool
|
||||||
|
```
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/slice"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
slice1 := []int{1, 2, 3}
|
||||||
|
slice2 := []int{1, 2, 3}
|
||||||
|
slice3 := []int{3, 2, 1}
|
||||||
|
|
||||||
|
res1 := slice.Equal(slice1, slice2)
|
||||||
|
res2 := slice.Equal(slice1, slice3)
|
||||||
|
|
||||||
|
fmt.Println(res1) //true
|
||||||
|
fmt.Println(res2) //false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="EqualWith">EqualWith</span>
|
||||||
|
<p>Check if two slices are equal with comparator funcation.comparator signature: func(a interface{}, b interface{}) bool</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func EqualWith(slice1, slice2 interface{}, comparator interface{}) bool
|
||||||
|
```
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/slice"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
slice1 := []int{1, 2, 3}
|
||||||
|
slice2 := []int{2, 4, 6}
|
||||||
|
|
||||||
|
isDouble := func(a, b int) bool {
|
||||||
|
return b == a*2
|
||||||
|
}
|
||||||
|
|
||||||
|
res := slice.EqualWith(slice1, slice2, isDouble)
|
||||||
|
|
||||||
|
fmt.Println(res) //true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### <span id="Every">Every</span>
|
### <span id="Every">Every</span>
|
||||||
<p>Return true if all of the values in the slice pass the predicate function. The function signature should be func(index int, value interface{}) bool.</p>
|
<p>Return true if all of the values in the slice pass the predicate function. The function signature should be func(index int, value interface{}) bool.</p>
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import (
|
|||||||
- [DifferenceBy](#DifferenceBy)
|
- [DifferenceBy](#DifferenceBy)
|
||||||
- [DeleteByIndex](#DeleteByIndex)
|
- [DeleteByIndex](#DeleteByIndex)
|
||||||
- [Drop](#Drop)
|
- [Drop](#Drop)
|
||||||
|
- [Equal](#Equal)
|
||||||
|
- [EqualWith](#EqualWith)
|
||||||
- [Every](#Every)
|
- [Every](#Every)
|
||||||
- [Filter](#Filter)
|
- [Filter](#Filter)
|
||||||
- [Find](#Find)
|
- [Find](#Find)
|
||||||
@@ -329,6 +331,68 @@ func main() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="Equal">Equal</span>
|
||||||
|
<p>检查两个切片是否相等,相等条件:切片长度相同,元素顺序和值都相同</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func Equal(slice1, slice2 interface{}) bool
|
||||||
|
```
|
||||||
|
<b>例子:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/slice"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
slice1 := []int{1, 2, 3}
|
||||||
|
slice2 := []int{1, 2, 3}
|
||||||
|
slice3 := []int{3, 2, 1}
|
||||||
|
|
||||||
|
res1 := slice.Equal(slice1, slice2)
|
||||||
|
res2 := slice.Equal(slice1, slice3)
|
||||||
|
|
||||||
|
fmt.Println(res1) //true
|
||||||
|
fmt.Println(res2) //false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="EqualWith">EqualWith</span>
|
||||||
|
<p>检查两个切片是否相等,相等条件:对两个切片的元素调用比较函数comparator,返回true。 comparator函数签名: func(a interface{}, b interface{}) bool</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func EqualWith(slice1, slice2 interface{}, comparator interface{}) bool
|
||||||
|
```
|
||||||
|
<b>例子:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/slice"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
slice1 := []int{1, 2, 3}
|
||||||
|
slice2 := []int{2, 4, 6}
|
||||||
|
|
||||||
|
isDouble := func(a, b int) bool {
|
||||||
|
return b == a*2
|
||||||
|
}
|
||||||
|
|
||||||
|
res := slice.EqualWith(slice1, slice2, isDouble)
|
||||||
|
|
||||||
|
fmt.Println(res) //true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### <span id="Every">Every</span>
|
### <span id="Every">Every</span>
|
||||||
<p>如果切片中的所有值都通过谓词函数,则返回true。 函数签名应该是func(index int, value interface{}) bool</p>
|
<p>如果切片中的所有值都通过谓词函数,则返回true。 函数签名应该是func(index int, value interface{}) bool</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user