databroker: fix fast forward (#4194)

databroker: fix fast forward (#4192)

* databroker: sort configs

* databroker: fix fast-forward

* newest not oldest

Co-authored-by: Caleb Doxsey <cdoxsey@pomerium.com>
This commit is contained in:
backport-actions-token[bot] 2023-05-23 15:47:07 -06:00 committed by GitHub
parent ca59798540
commit 4aa6960e06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 113 additions and 47 deletions

View file

@ -33,6 +33,13 @@ func Remove[S ~[]E, E comparable](s S, e E) S {
return ns
}
// Reverse reverses a slice's order.
func Reverse[S ~[]E, E comparable](s S) {
for i := 0; i < len(s)/2; i++ {
s[i], s[len(s)-1-i] = s[len(s)-1-i], s[i]
}
}
// Unique returns the unique elements of s.
func Unique[S ~[]E, E comparable](s S) S {
var ns S
@ -45,3 +52,17 @@ func Unique[S ~[]E, E comparable](s S) S {
}
return ns
}
// UniqueBy returns the unique elements of s using a function to map elements.
func UniqueBy[S ~[]E, E any, V comparable](s S, by func(E) V) S {
var ns S
h := map[V]struct{}{}
for _, el := range s {
v := by(el)
if _, ok := h[v]; !ok {
h[v] = struct{}{}
ns = append(ns, el)
}
}
return ns
}