This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-02
Channels
- # announcements (26)
- # architecture (29)
- # babashka (8)
- # beginners (91)
- # calva (70)
- # cider (7)
- # circleci (2)
- # cljs-dev (1)
- # clojure (79)
- # clojure-australia (2)
- # clojure-dev (3)
- # clojure-europe (40)
- # clojure-italy (2)
- # clojure-losangeles (4)
- # clojure-nl (4)
- # clojure-uk (4)
- # clojurescript (34)
- # cursive (13)
- # datomic (16)
- # defnpodcast (2)
- # emacs (11)
- # events (1)
- # fulcro (13)
- # graalvm (17)
- # gratitude (3)
- # instaparse (10)
- # introduce-yourself (2)
- # jobs (1)
- # jobs-discuss (5)
- # juxt (3)
- # kaocha (5)
- # meander (5)
- # membrane (2)
- # nextjournal (43)
- # off-topic (42)
- # pathom (52)
- # pedestal (8)
- # portal (3)
- # rdf (2)
- # re-frame (10)
- # reveal (21)
- # shadow-cljs (56)
- # slack-help (7)
- # vim (33)
- # xtdb (43)
bb master was updated to clojure 1.11 beta1.
$ bash <(curl ) --version 0.7.5-SNAPSHOT --dir .
$ ./bb doc iteration
-------------------------
clojure.core/iteration
([step & {:keys [somef vf kf initk], :or {vf identity, kf identity, somef some?, initk nil}}])
🙌 8
@U01BDT7622X would be very interested in an example if possible
@U088NU894 here is simple example:
(defn describe-instances
"Describe instances, returning lazy sequence."
[ec2]
(->> (iteration
(fn [token]
(aws/invoke ec2 (cond-> {:op :DescribeInstances}
token (assoc :request {:nextToken token}))))
:kf :nextToken
:vf :Reservations)
(into [] cat)))
1
1
âž• 1
used on jvm to iterate sentry events
(defn
get-api
[opts]
(merge
{:oauth-token (sentry-token)
:method :get
:client @sni/default-client}
(update opts :url get-url)))
(defn
request!
[req]
(let [resp @(client/request req)
{retry-after :retry_after
:as body}
(->
resp
:body
(json/read-str :key-fn keyword))]
(if
(not retry-after)
(assoc resp :body body)
(do
(async/<!!
(async/timeout retry-after))
(recur req)))))
(defn link->next-cursor-data
[link]
(->>
(str/split link #";")
(take-last 3)
(into
{}
(comp
(keep
#(rest
(re-find #" (\w+)=\"(.*)\"" %)))
(map
(juxt keyword identity))))))
(defn
iteration*
[api]
(eduction
cat
(iteration
(fn step! [cursor]
(let [req (cond->
api
cursor
(assoc-in
[:query-params "cursor"]
cursor))]
(request! req)))
{:vf :body
:kf (comp
(fn
[{:keys [:results :cursor]}]
(when
(= results "true")
cursor))
link->next-cursor-data
:link
:headers)})))
(defn
events-iteration
[]
(iteration*
(get-api
{:url (str
"/projects/"
(:org.sg.sentry/organisation-slug
config)
"/"
(:org.sg.sentry/project-slug
config)
"/events/")
:query-params {"full" true}})))
bit messy with this link->next-cursor-data parsing the link in the headers but this works well 1