You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
466 B
Go

3 years ago
package merge
import (
"fmt"
)
type Table[K comparable, V Merges[V]] map[K]V
func (t Table[K, V]) Merge(from Table[K, V]) error {
for k, v := range from {
e, ok := t[k]
if !ok {
var z V
z = z.MergeIdentity()
if err := z.Merge(v); err != nil {
return fmt.Errorf("tables failed to merge: %w", err)
}
t[k] = z
3 years ago
continue
}
if err := e.Merge(v); err != nil {
return fmt.Errorf("tables failed to merge: %w", err)
}
}
return nil
}