mirror of
https://github.com/samber/lo.git
synced 2026-04-22 15:37:14 +08:00
fa095e4b4f
* fix(doc): fix go playground demo URL * fix(doc): add more go playground demo URL
27 lines
553 B
Markdown
27 lines
553 B
Markdown
---
|
|
name: Clone
|
|
slug: clone
|
|
sourceRef: slice.go#L741
|
|
category: core
|
|
subCategory: slice
|
|
playUrl: https://go.dev/play/p/66LJ2wAF0rN
|
|
variantHelpers:
|
|
- core#slice#clone
|
|
similarHelpers:
|
|
- core#slice#repeat
|
|
- core#slice#fill
|
|
position: 160
|
|
signatures:
|
|
- "func Clone[T any, Slice ~[]T](collection Slice) Slice"
|
|
---
|
|
|
|
Returns a shallow copy of the collection.
|
|
|
|
```go
|
|
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}
|
|
```
|