mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-19 03:54:55 +02:00
changes
* move error-related code for groups to its own file * update group avatar logic remove unused/duplicate logic * update `FindGroupsOptions.ToConds()` allow passing `-1` as the `ParentGroupID`, meaning "find matching groups regardless of the parent group id" * add `DedupeBy` function to container module this removes duplicate items from a slice using a custom function * add `SliceMap` util works like javascripts's `Array.prototoype.map`, taking in a slice and transforming each element with the provided function * add group service functions included so far: - avatar uploading/deletion - group deletion - group creation - group moving (including moving item inside a group) - group update - team management - add team - remove team - update team permissions - recalculating team access (in event of group move) - group searching (only used in frontend/web components for now)
This commit is contained in:
@@ -19,3 +19,16 @@ func FilterSlice[E any, T comparable](s []E, include func(E) (T, bool)) []T {
|
||||
}
|
||||
return slices.Clip(filtered)
|
||||
}
|
||||
|
||||
func DedupeBy[E any, I comparable](s []E, id func(E) I) []E {
|
||||
filtered := make([]E, 0, len(s)) // slice will be clipped before returning
|
||||
seen := make(map[I]bool, len(s))
|
||||
for i := range s {
|
||||
itemId := id(s[i])
|
||||
if _, ok := seen[itemId]; !ok {
|
||||
filtered = append(filtered, s[i])
|
||||
seen[itemId] = true
|
||||
}
|
||||
}
|
||||
return slices.Clip(filtered)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user