5c253b3592
Feature/docinit * createunittests * cleanup * skip * cleanup
42 lines
715 B
Go
42 lines
715 B
Go
package validation
|
|
|
|
import "fmt"
|
|
|
|
func GetUpdatedValue[T any](def T, new *T) T {
|
|
if new != nil {
|
|
return *new
|
|
}
|
|
return def
|
|
}
|
|
|
|
func DeduplicateArray[T comparable](arr []T) []T {
|
|
occurred := make(map[T]bool)
|
|
result := []T{}
|
|
|
|
for _, value := range arr {
|
|
if !occurred[value] {
|
|
occurred[value] = true
|
|
result = append(result, value)
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
func NormalizeInClosedInterval(updated **int32, current int32, min int32, max int32) error {
|
|
if updated == nil || *updated == nil {
|
|
return nil
|
|
}
|
|
|
|
if **updated == current {
|
|
*updated = nil
|
|
return nil
|
|
}
|
|
|
|
if **updated < min || **updated > max {
|
|
return fmt.Errorf("update must be in range: %d <= update <= %d", min, max)
|
|
}
|
|
|
|
return nil
|
|
}
|