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

doc: update doc for new functions

This commit is contained in:
dudaodong
2024-03-01 22:38:57 +08:00
parent a62ad71791
commit 3d1bd08434
6 changed files with 91 additions and 2 deletions

View File

@@ -883,7 +883,7 @@ func main() {
### <span id="ToStdBase64">ToStdBase64</span>
<p>值转换为 StdBase64 编码的字符串。error 类型的数据也会把 error 的原因进行编码,复杂的结构会转为 JSON 格式的字符串</p>
<p>值转换为StdBase64编码的字符串。error类型的数据也会把error的原因进行编码复杂的结构会转为JSON格式的字符串</p>
<b>函数签名:</b>

View File

@@ -93,6 +93,7 @@ import (
- [KeyBy](#KeyBy)
- [Join](#Join)
- [Partition](#Partition)
- [SetToDefaultIf](#SetToDefaultIf)
<div STYLE="page-break-after: always;"></div>
@@ -2568,4 +2569,35 @@ func main() {
// Output:
// okk
}
```
### <span id="SetToDefaultIf">SetToDefaultIf</span>
<p>根据给定给定的predicate判定函数来修改切片中的元素。对于满足的元素将其替换为指定的默认值同时保持元素在切片中的位置不变。函数返回修改后的切片以及被修改的元素个数。</p>
<b>函数签名:</b>
```go
func SetToDefaultIf[T any](slice []T, predicate func(T) bool) ([]T, int)
```
<b>示例:</b>
```go
import (
"fmt"
"github.com/duke-git/lancet/v2/slice"
)
func main() {
strs := []string{"a", "b", "a", "c", "d", "a"}
modifiedStrs, count := slice.SetToDefaultIf(strs, func(s string) bool { return "a" == s })
fmt.Println(modifiedStrs)
fmt.Println(count)
// Output:
// [ b c d ]
// 3
}
```