Created
January 15, 2022 00:16
-
-
Save kennyjwilli/65dfbc30c75d76ba2e22cb044c3f8d1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn iteration-op-map | |
"Iterates an op-map based step. Useful in aws-api and gcp-api. Returns a list | |
of results from each page after applying :itemsf. If an anomaly is returned | |
from invoke-fn, it will be included in the list." | |
[invoke-fn op-map {:keys [request-key response-key itemsf]}] | |
(iteration | |
(fn [next-token] | |
(invoke-fn | |
(cond-> op-map | |
next-token (assoc-in [:request request-key] next-token)))) | |
:kf (fn [ret] | |
(let [k (response-key ret)] | |
(when (and k (if (string? k) (not (str/blank? k)) true)) | |
k))) | |
:vf (fn [ret] | |
(if (:cognitect.anomalies/category ret) | |
ret | |
(itemsf ret))))) | |
(comment | |
(iteration-op-map | |
#(aws/invoke client %) | |
{:op :ListObjectsV2 | |
:request {:Bucket "my-bucket"}} | |
{:request-key :ContinuationToken | |
:response-key :ContinuationToken | |
:itemsf :Contents})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment