Files
lo/docs/data/core-clone.md
T
quexer 41f7af2114 Add Clone function to return shallow copy of slice collections (#732)
* Initial plan

* Add Clone function to return shallow copy of slice collection

Co-authored-by: quexer <92157+quexer@users.noreply.github.com>

* Update slice.go

Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>

* Update slice_test.go

Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>

* doc and test

* Apply suggestions from code review

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: quexer <92157+quexer@users.noreply.github.com>
Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
2025-11-06 17:47:04 +01:00

519 B

name, slug, sourceRef, category, subCategory, playUrl, variantHelpers, similarHelpers, position, signatures
name slug sourceRef category subCategory playUrl variantHelpers similarHelpers position signatures
Clone clone slice.go#L741 core slice
core#slice#clone
core#slice#repeat
core#slice#fill
160
func Clone[T any, Slice ~[]T](collection Slice) Slice

Returns a shallow copy of the collection.

in := []int{1, 2, 3, 4, 5}
cloned := lo.Clone(in)
// Verify it's a different slice by checking that modifying one doesn't affect the other
in[0] = 99
// cloned is []int{1, 2, 3, 4, 5}