This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-02
Channels
- # aleph (5)
- # beginners (112)
- # boot (137)
- # cider (10)
- # cljs-dev (36)
- # cljsrn (2)
- # clojure (118)
- # clojure-argentina (1)
- # clojure-berlin (1)
- # clojure-brasil (3)
- # clojure-dev (4)
- # clojure-italy (2)
- # clojure-nl (13)
- # clojure-russia (23)
- # clojure-spec (5)
- # clojure-uk (53)
- # clojurescript (344)
- # clojutre (1)
- # core-async (65)
- # cursive (9)
- # datascript (7)
- # datomic (28)
- # devops (1)
- # emacs (16)
- # events (1)
- # jobs (5)
- # keechma (18)
- # lumo (56)
- # off-topic (7)
- # om (3)
- # onyx (14)
- # protorepl (21)
- # re-frame (3)
- # reagent (20)
- # ring (12)
- # ring-swagger (9)
- # specter (17)
- # unrepl (14)
- # vim (14)
- # yada (22)
Hia, I’m having trouble converting the following code to d/loop
:
(loop [messages (fetch-messages auth-token query nil)
result []]
(let [next-token (:nextPageToken messages)]
(if (nil? next-token)
(d/future (concat result (:messages @messages)))
(recur (fetch-messages auth-token query next-token)
result))
))
I must have misunderstood something, this is my attempt:
(d/loop [messages (fetch-messages auth-token query nil)
result []]
(-> messages
(d/chain
(fn [msgs]
(let [next-token (:nextPageToken msgs)]
(println "NEXT:" next-token)
(if (nil? next-token)
(concat result (:messages msgs))
(d/recur (fetch-messages auth-token query next-token))
)
)))
(d/catch
(fn [ex]
(println "ERROR" ex)
ex))
))
mping: it looks like you're d/recur
is missing one argument, it should probably be something like this (didn't check with compiler):
(d/loop [token nil
result []]
(-> (fetch-messages auth-token query token)
(d/chain
(fn [msgs]
(let [next-token (:nextPageToken msgs)]
(println "NEXT:" next-token)
(if (nil? next-token)
(concat result (:messages msgs))
(d/recur next-token (concat result (:messages msgs)))))))
(d/catch
(fn [ex]
(println "ERROR" ex)
ex))))