-
Notifications
You must be signed in to change notification settings - Fork 18.7k
fmt: add Join function for formatting and joining slice elements #76737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
This PR (HEAD: 8b7b3bf) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/727840. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/727840. |
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/727840. |
|
Message from Vikash Kumar: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/727840. |
|
Message from Sean Liao: Patch Set 1: Hold+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/727840. |
|
Message from Vikash Kumar: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/727840. |
|
This PR is being closed because golang.org/cl/727840 has been abandoned. see the issue, but it seems we decided against having fmt handle slices |
This change adds a generic Join function to the fmt package that
formats each element of a slice using the default format (%v) and
joins them with a separator string. This complements the existing
fmt formatting functions and provides a convenient way to format
and join slice elements of any type.
The function signature is:
func Join[T any](elems []T, sep string) string
Key features:
This is similar to strings.Join but works with any type and uses
fmt formatting, making it useful for formatting slices of integers,
floats, structs, or any other type.
The implementation includes comprehensive test coverage for edge
cases including empty/nil slices, various types, special values,
and different separator formats.