Skip to content

Add a Join() function to the lo package#899

Open
eliotttak wants to merge 2 commits into
samber:masterfrom
eliotttak:master
Open

Add a Join() function to the lo package#899
eliotttak wants to merge 2 commits into
samber:masterfrom
eliotttak:master

Conversation

@eliotttak
Copy link
Copy Markdown

@eliotttak eliotttak commented May 27, 2026

Describe your changes

I added a Join() function to the lo package.
It takes a collection and a separator (that can be any type) and returns a string that contains
every item, separated by the specified separator.

It uses fmt to convert list items and separator to string, and a strings.Builder to construct it.
I created an example on pkg.go.dev but because the import path is github.com/samber/lo, it will be available only if you accept the PR.

I wrote various tests in ./slice_test.go. Feel free to look at them if you want to verify, I tried to cover every case where my function could bug.

Checklist before requesting a review

  • 👓 I have performed a self-review of my code
  • 👶 This helper does not already exist
  • 🧪 This helper is tested
  • 🏎️ My code limits memory allocation and is fast
  • [?] 🧞‍♂️ This helper is immutable and my tests prove it
  • [?] ✍️ I implemented the parallel, iterator and mutable variants
  • 🔬 An example has been added to lo_example_test.go
  • ⛹️ An example has been created on https://go.dev/play and added in comments
  • 📖 My helper has been added to documentation
    • in README.md
    • in docs/data/*.md
    • in docs/static/llms.txt

Conventions

  • Returning (ok bool) is often better than (err error)
  • panic(...) must be limited
  • Helpers should receive variadic arguments when relevent
  • Add variants of your helper when relevant:
    • Variable number of arguments: lo.Must0, lo.Must1, lo.Must2, ...
    • Predicate with index: lo.SliceToMap vs lo.SliceToMapI
    • With lazy callback: lo.Ternary vs lo.TernaryF
    • ...

@eliotttak
Copy link
Copy Markdown
Author

Fixes #351.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant