mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
feat(app/edge-stacks): summarize the edge stack statuses in the backend (#818)
This commit is contained in:
parent
363a62d885
commit
e1c480d3c3
21 changed files with 645 additions and 312 deletions
21
api/slicesx/unique.go
Normal file
21
api/slicesx/unique.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package slicesx
|
||||
|
||||
func Unique[T comparable](items []T) []T {
|
||||
return UniqueBy(items, func(item T) T {
|
||||
return item
|
||||
})
|
||||
}
|
||||
|
||||
func UniqueBy[ItemType any, ComparableType comparable](items []ItemType, accessorFunc func(ItemType) ComparableType) []ItemType {
|
||||
includedItems := make(map[ComparableType]bool)
|
||||
result := []ItemType{}
|
||||
|
||||
for _, item := range items {
|
||||
if _, isIncluded := includedItems[accessorFunc(item)]; !isIncluded {
|
||||
includedItems[accessorFunc(item)] = true
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue