samber / lo

💥 A Lodash-style Go library based on Go 1.18+ Generics (map, filter, contains, find...)
https://pkg.go.dev/github.com/samber/lo
MIT License
17.93k stars 824 forks source link

Add helper function for Slice deep copy #274

Open CorentinClabaut opened 1 year ago

CorentinClabaut commented 1 year ago

It would be helpful to have a function like follows to simply create a deep copy of a slice. func DeepCopy[T any](collection []T) []T

No need for map deep copy function as it can be done with lo.Assign passing only one map in.

trungdlp-wolffun commented 1 year ago

Quickly, you can try https://github.com/jinzhu/copier

CorentinClabaut commented 1 year ago

Looks good @trungdlp-wolffun I didn't know this package, it seems to handle a lot of use cases.

In any case, it feels like this simple helper function can still be useful in the package for simple cases.