mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 19:21:50 +00:00
In a few places we have different patterns around pagination:
- Passing a closure in
- Returning a cursor for the client to use
- Just collect everything into a big slice
Other go libraries often will setup pagination patterns / use
interfaces. The API I quite like is the stripe-go one which is minimal
and reminds me a lot of Scanner from the stdlib. You just do something
like
for it.Next() {
doSomething(it.Current())
}
if it.Err() != nil {
handle
}
I imagine if we had this interface a few useful methods like
Map[A,B](func(A() B, Iterator[A]) Iterator[B]
Collect(Iterator[T]) ([]T, error)
etc. Basically could implement the same functions as present in
https://pkg.go.dev/golang.org/x/exp/slices
|
||
|---|---|---|
| .. | ||
| functions_test.go | ||
| functions.go | ||
| iterator_test.go | ||
| iterator.go | ||