1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 23:22: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

@@ -1398,3 +1398,16 @@ func Frequency[T comparable](slice []T) map[T]int {
return result
}
// JoinFunc joins the slice elements into a single string with the given separator.
// Play: todo
func JoinFunc[T any](slice []T, sep string, transform func(T) T) string {
var buf strings.Builder
for i, v := range slice {
if i > 0 {
buf.WriteString(sep)
}
buf.WriteString(fmt.Sprint(transform(v)))
}
return buf.String()
}