Repository navigation
Conversation
Fill was accidentally defined in slice_example_test.go instead of slice.go, causing it to not be exported as part of the public mutable package. This moves func Fill into slice.go, adds ExampleFill() in slice_example_test.go, and updates the source reference and example in docs/data/mutable-fill.md.
rahul05ranjan
left a comment
There was a problem hiding this comment.
Verified the bug and the fix — this was a real export failure, not just a misplaced definition. Since Fill was declared inside slice_example_test.go, it only existed in the test build of the package: any consumer importing github.com/samber/lo/mutable got undefined: mutable.Fill, while the package's own examples kept passing because they live in the same test package. Your description matches exactly how Go handles _test.go files.
Details I checked:
- The new location lines up with the docs metadata:
sourceRef: mutable/slice.go#L78matches the convention used by the neighboring entries (mutable-reverse.mdpoints atslice.go#L66, which is precisely itsfunc Reverseline, andfunc Filllands on line 78 after the move). - The doc example now follows the mutable-package convention —
import lom "github.com/samber/lo/mutable"+lom.Fill(...), same style as the Reverse docs. The old doc block showinglo.Fillwas doubly wrong since that helper lives inloroot as the immutableFilland this one never existed asmutable.Fillfor consumers. - Turning the stray generic function into a proper
func ExampleFill()with an// Output:block means it's now both compiled ingo testand rendered in godoc, which the previous construction (an unexported-looking generic func in an example file, which godoc would have ignored) never achieved.
One thing you might double-check: since Fill was invisible to consumers until now, this is effectively a new symbol in the public mutable API — worth a line in the release notes if the project tracks those per-helper (the changelog-generation setup will probably pick it up automatically from the move, but worth confirming it lands under "added" rather than being silent).
|
Thanks a lot for the thorough review and verification, @rahul05ranjan! Good point regarding the release notes / changelog — since |
Describe your changes
In the
mutablepackage,func Fillwas accidentally declared insidemutable/slice_example_test.goinstead ofmutable/slice.go.Because Go omits
_test.gofiles during compilation for external consumers,mutable.Fillwas not actually exported in the public API when importinggithub.com/samber/lo/mutable(undefined: mutable.Fill).Changes made:
func Fill: Moved frommutable/slice_example_test.gotomutable/slice.go.ExampleFill: Added a runnableExampleFill()inmutable/slice_example_test.goto verify the example and keep documentation examples complete.sourceRefindocs/data/mutable-fill.mdto point tomutable/slice.go#L78.docs/data/mutable-fill.mdto uselom.Fillinstead oflo.Fill.Verification:
go doc ./mutablenow correctly lists: