Add an error return to the EachPage closure.
Because the Extract functions, at the very least, have an error parameter, and it's
kind of a pain to capture it outside the closure.
diff --git a/collections.go b/collections.go
index ba83965..1830ff0 100644
--- a/collections.go
+++ b/collections.go
@@ -41,7 +41,7 @@
// EachPage iterates over each page returned by a Pager, yielding one at a time to a handler function.
// Return "false" from the handler to prematurely stop iterating.
-func (p Pager) EachPage(handler func(Page) bool) error {
+func (p Pager) EachPage(handler func(Page) (bool, error)) error {
currentURL := p.initialURL
for {
currentPage, err := p.advance(currentURL)
@@ -49,7 +49,11 @@
return err
}
- if !handler(currentPage) {
+ ok, err := handler(currentPage)
+ if err != nil {
+ return err
+ }
+ if !ok {
return nil
}