mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-17 03:02:28 +08:00
doc: add document for AppendIfAbsent function
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
|||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## Index
|
## Index
|
||||||
|
- [AppendIfAbsent](#AppendIfAbsent)
|
||||||
- [Contain](#Contain)
|
- [Contain](#Contain)
|
||||||
- [ContainSubSlice](#ContainSubSlice)
|
- [ContainSubSlice](#ContainSubSlice)
|
||||||
- [Chunk](#Chunk)
|
- [Chunk](#Chunk)
|
||||||
@@ -69,6 +70,33 @@ import (
|
|||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
|
### <span id="AppendIfAbsent">AppendIfAbsent</span>
|
||||||
|
<p>If slice doesn't contain the value, append it to the slice.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func AppendIfAbsent[T comparable](slice []T, value T) []T
|
||||||
|
```
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/slice"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
strs := []string{"a", "b"}
|
||||||
|
res1 := slice.AppendIfAbsent(strs, "a")
|
||||||
|
fmt.Println(res1) //[]string{"a", "b"}
|
||||||
|
|
||||||
|
res2 := slice.AppendIfAbsent(strs, "cannot")
|
||||||
|
fmt.Println(res2"}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### <span id="Contain">Contain</span>
|
### <span id="Contain">Contain</span>
|
||||||
<p>Check if the value is in the slice or not.</p>
|
<p>Check if the value is in the slice or not.</p>
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
|
- [AppendIfAbsent](#AppendIfAbsent)
|
||||||
- [Contain](#Contain)
|
- [Contain](#Contain)
|
||||||
- [ContainSubSlice](#ContainSubSlice)
|
- [ContainSubSlice](#ContainSubSlice)
|
||||||
- [Chunk](#Chunk)
|
- [Chunk](#Chunk)
|
||||||
@@ -69,6 +70,34 @@ import (
|
|||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
|
### <span id="AppendIfAbsent">AppendIfAbsent</span>
|
||||||
|
<p>当前切片中不包含值时,将该值追加到切片中</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func AppendIfAbsent[T comparable](slice []T, value T) []T
|
||||||
|
```
|
||||||
|
<b>例子:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/slice"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
strs := []string{"a", "b"}
|
||||||
|
res1 := slice.AppendIfAbsent(strs, "a")
|
||||||
|
fmt.Println(res1) //[]string{"a", "b"}
|
||||||
|
|
||||||
|
res2 := slice.AppendIfAbsent(strs, "cannot")
|
||||||
|
fmt.Println(res2"}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### <span id="Contain">Contain</span>
|
### <span id="Contain">Contain</span>
|
||||||
<p>判断slice是否包含value</p>
|
<p>判断slice是否包含value</p>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user