mirror of
https://github.com/go-task/task.git
synced 2025-02-05 13:25:14 +02:00
f22389a824
* refactor: move deepcopy into its own package * feat: add generic orderedmap implementation * refactor: implement tasks with orderedmap * feat: implement sort flag for all task outputs * refactor: implement vars with orderedmap * chore: docs * fix: linting issues * fix: non deterministic behavior in tests
36 lines
569 B
Go
36 lines
569 B
Go
package deepcopy
|
|
|
|
type Copier[T any] interface {
|
|
DeepCopy() T
|
|
}
|
|
|
|
func Slice[T any](orig []T) []T {
|
|
if orig == nil {
|
|
return nil
|
|
}
|
|
c := make([]T, len(orig))
|
|
for i, v := range orig {
|
|
if copyable, ok := any(v).(Copier[T]); ok {
|
|
c[i] = copyable.DeepCopy()
|
|
} else {
|
|
c[i] = v
|
|
}
|
|
}
|
|
return c
|
|
}
|
|
|
|
func Map[K comparable, V any](orig map[K]V) map[K]V {
|
|
if orig == nil {
|
|
return nil
|
|
}
|
|
c := make(map[K]V, len(orig))
|
|
for k, v := range orig {
|
|
if copyable, ok := any(v).(Copier[V]); ok {
|
|
c[k] = copyable.DeepCopy()
|
|
} else {
|
|
c[k] = v
|
|
}
|
|
}
|
|
return c
|
|
}
|