diff options
author | 2023-11-20 12:22:28 +0000 | |
---|---|---|
committer | 2023-11-20 12:22:28 +0000 | |
commit | 16275853eb8a43e0b113d476b896de53585c1281 (patch) | |
tree | b2e0e6b4fc7cd4f1cc781e5c305ec24df38e6718 /internal/paging/boundary.go | |
parent | [chore]: Bump github.com/tdewolff/minify/v2 from 2.20.6 to 2.20.7 (#2370) (diff) | |
download | gotosocial-16275853eb8a43e0b113d476b896de53585c1281.tar.xz |
[bugfix] self-referencing collection pages for status replies (#2364)
Diffstat (limited to 'internal/paging/boundary.go')
-rw-r--r-- | internal/paging/boundary.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/internal/paging/boundary.go b/internal/paging/boundary.go index 15af65e0c..83d265515 100644 --- a/internal/paging/boundary.go +++ b/internal/paging/boundary.go @@ -131,3 +131,20 @@ func (b Boundary) Find(in []string) int { } return -1 } + +// Boundary_FindFunc is functionally equivalent to Boundary{}.Find() but for an arbitrary type with ID. +// Note: this is not a Boundary{} method as Go generics are not supported in method receiver functions. +func Boundary_FindFunc[T any](b Boundary, in []T, get func(T) string) int { //nolint:revive + if get == nil { + panic("nil function") + } + if b.Value == "" { + return -1 + } + for i := range in { + if get(in[i]) == b.Value { + return i + } + } + return -1 +} |