Skip to content

Commit

Permalink
generics
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Mar 25, 2024
1 parent 1fd6629 commit 61b9a47
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/structures/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,16 @@ func unmarshalFileFS(fsys fs.FS, filename string, data any) error {
return dec.Decode(data)
}

// except returns the first string of the slice that is not s, or empty string
// except returns the first element of the slice that is not s, or zero value
// if not found.
func except(s string, ss []string) string {
func except[S ~[]T, T comparable](s T, ss S) T {
var zero T
for _, t := range ss {
if t != s {
return t
}
}
return ""
return zero
}

// mostFrequentMember attempts to identify the current user in the index. It uses the DMs of
Expand Down

0 comments on commit 61b9a47

Please sign in to comment.