Skip to content

Commit d221e6e

Browse files
committed
update readme regarding pagination
1 parent 04dba95 commit d221e6e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

README.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Get the latest release and then:
1616
(babashka.pods/load-pod ["./pod-tzzh-aws"])
1717
(require '[pod.tzzh.dynamodb :as d])
1818
(require '[pod.tzzh.s3 :as s3])
19+
(require '[pod.tzzh.paginator :as p])
1920

2021

2122
(d/list-tables)
@@ -37,12 +38,19 @@ Get the latest release and then:
3738

3839
(s3/list-buckets)
3940

40-
(s3/list-objects-v2-pages {:Bucket "some-bucket"
41-
:Prefix "some-prefix/something/"})
42-
;; this returns a list of all the pages i.e a list of ListObjectsV2Output
41+
(let [s3-paginator (p/get-paginator s3/list-objects-v2-pages)]
42+
(s3-paginator {:Bucket "some-bucket"
43+
:Prefix "some-prefix/something/"}))
44+
;; this returns a list of all the pages i.e a list of ListObjectsV2Output that are lazily fetched
4345
```
4446

4547
## Paginators
4648

47-
In the Go sdk paginators use a function argument which is called on each page and returns a boolean that tells when to stop iterating.
48-
That behaviour would be really tricky to implement so instead the paginators return a list of all the pages.
49+
In the Go sdk paginators take a function argument which is called on each page and returns a boolean that tells when to stop iterating, and the paginator itself doesn't return anything.
50+
For example the signature of `ListObjectsV2Pages` is
51+
```go
52+
func (c *S3) ListObjectsV2Pages(input *ListObjectsV2Input, fn func(*ListObjectsV2Output, bool) bool) error
53+
```
54+
Whereas in the Python sdk, the paginators are instead generators that lazily loads the pages.
55+
This approach is more functional and has been copied here.
56+
To use it you need to use the `get-paginator` fn from the `pod.tzzh.paginator` namespace and pass the fn you need to use as an argument to `get-paginator` as shown in the example above.

0 commit comments

Comments
 (0)