Add collect to pagination

With #2099 (closed), pagination was added which is already great.

But I think in many cases, it is a but cumbersome to use when one just wants all returned items in a slice.

So I thought about adding another helper like this one:

func ScanAndCollect[T any](f func(p PaginationOptionFunc) ([]T, *Response, error)) ([]T, error) {
	it, hasErr := Scan(f)
	allItems := slices.Collect(it)
	if err := hasErr(); err != nil {
		return nil, err
	}
	return allItems, nil
}

Which basically just uses Scan and then collects the items and the error and simply returns them. It's just something small but could help a lot as the intermediate iterator and hasError method do not need to be stored.

Assignee Loading
Time tracking Loading