1
0
mirror of https://github.com/go-task/task.git synced 2025-11-23 22:24:45 +02:00

feat: use external package for ordered maps (#1797)

This commit is contained in:
Pete Davison
2024-12-30 17:54:36 +00:00
committed by GitHub
parent dbe6e41ac8
commit 2965841eb7
24 changed files with 499 additions and 486 deletions

View File

@@ -2,6 +2,8 @@ package deepcopy
import (
"reflect"
"github.com/elliotchance/orderedmap/v2"
)
type Copier[T any] interface {
@@ -38,6 +40,21 @@ func Map[K comparable, V any](orig map[K]V) map[K]V {
return c
}
func OrderedMap[K comparable, V any](orig *orderedmap.OrderedMap[K, V]) *orderedmap.OrderedMap[K, V] {
if orig.Len() == 0 {
return orderedmap.NewOrderedMap[K, V]()
}
c := orderedmap.NewOrderedMap[K, V]()
for pair := orig.Front(); pair != nil; pair = pair.Next() {
if copyable, ok := any(pair.Value).(Copier[V]); ok {
c.Set(pair.Key, copyable.DeepCopy())
} else {
c.Set(pair.Key, pair.Value)
}
}
return c
}
// TraverseStringsFunc runs the given function on every string in the given
// value by traversing it recursively. If the given value is a string, the
// function will run on a copy of the string and return it. If the value is a