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

feat: add Join

This commit is contained in:
dudaodong
2023-07-10 10:51:43 +08:00
parent 36ef5b3bd3
commit d5334f892f
5 changed files with 108 additions and 1 deletions

View File

@@ -90,6 +90,7 @@ import (
- [UpdateAt](#UpdateAt)
- [Without](#Without)
- [KeyBy](#KeyBy)
- [Join](#Join)
<div STYLE="page-break-after: always;"></div>
@@ -2417,3 +2418,36 @@ func main() {
// map[1:a 2:ab 3:abc]
}
```
### <span id="Join">Join</span>
<p>Join the slice item with specify separator.</p>
<b>Signature:</b>
```go
func Join[T any](s []T, separator string) string
```
<b>Example:</b>
```go
import (
"fmt"
"github.com/duke-git/lancet/v2/slice"
)
func main() {
nums := []int{1, 2, 3, 4, 5}
result1 := slice.Join(nums, ",")
result2 := slice.Join(nums, "-")
fmt.Println(result1)
fmt.Println(result2)
// Output:
// 1,2,3,4,5
// 1-2-3-4-5
}
```