mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-23 19:49:13 +02:00
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:
parent
ca59798540
commit
4aa6960e06
4 changed files with 113 additions and 47 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue