sourcegraph/lib/iterator
Keegan Carruthers-Smith b14f7f0fcf
lib: generic iterator based on stripes iterator (#45017)
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
2022-12-05 11:55:11 +00:00
..
functions_test.go lib: generic iterator based on stripes iterator (#45017) 2022-12-05 11:55:11 +00:00
functions.go lib: generic iterator based on stripes iterator (#45017) 2022-12-05 11:55:11 +00:00
iterator_test.go lib: generic iterator based on stripes iterator (#45017) 2022-12-05 11:55:11 +00:00
iterator.go lib: generic iterator based on stripes iterator (#45017) 2022-12-05 11:55:11 +00:00