1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

feat: add JoinFunc

This commit is contained in:
dudaodong
2024-10-24 14:56:13 +08:00
parent 921f218ef7
commit 2015d36b08
5 changed files with 126 additions and 0 deletions

View File

@@ -106,6 +106,8 @@ import (
- [RightPadding](#RightPadding)
- [LeftPadding](#LeftPadding)
- [Frequency](#Frequency)
- [JoinFunc](#JoinFunc)
<div STYLE="page-break-after: always;"></div>
@@ -2984,4 +2986,34 @@ func main() {
// Output:
// map[a:1 b:2 c:3]
}
```
### <span id="JoinFunc">JoinFunc</span>
<p>将切片元素用给定的分隔符连接成一个单一的字符串。</p>
<b>函数签名:</b>
```go
func JoinFunc[T any](slice []T, sep string, transform func(T) T) string
```
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
```go
import (
"fmt"
"github.com/duke-git/lancet/v2/slice"
)
func main() {
result := slice.JoinFunc([]string{"a", "b", "c"}, ", ", func(s string) string {
return strings.ToUpper(s)
})
fmt.Println(result)
// Output:
// A, B, C
}
```