This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-23
Channels
- # announcements (3)
- # asami (5)
- # babashka (1)
- # beginners (38)
- # biff (4)
- # calva (12)
- # cider (2)
- # clj-commons (6)
- # clj-kondo (46)
- # clj-on-windows (1)
- # clojure (50)
- # clojure-europe (41)
- # clojure-nl (3)
- # clojure-norway (2)
- # clojure-uk (16)
- # clojured (3)
- # clojurescript (49)
- # conjure (1)
- # cursive (29)
- # datahike (6)
- # datascript (4)
- # emacs (70)
- # funcool (1)
- # google-cloud (12)
- # graalvm (10)
- # graalvm-mobile (7)
- # gratitude (4)
- # hyperfiddle (1)
- # joyride (26)
- # lsp (16)
- # malli (23)
- # nbb (5)
- # off-topic (23)
- # polylith (32)
- # re-frame (23)
- # releases (3)
- # remote-jobs (1)
- # reveal (3)
- # tools-build (16)
- # xtdb (50)
Is there something like Found it partition
that yields remaining elements if the don't fit the partition size?partition-all
partition-all
(https://clojuredocs.org/clojure.core/partition-all) is your friend!
Or, partition
with the optional pad. From the docs:
> If a pad collection is supplied, use its elements as necessary to complete last partition upto n items
What’s the transducer equivalent of run!
If you just want to do a side effect at the end of the transducer?
Thanks, I’ll give that a go.
ahhh that’s a good shout. I’ve hit a paginated api using iteration
and just want to log each item after doing some transforms.
(->> (iteration
(partial get-discord-guild-members! external-id)
:kf #(-> % last :user :id)
:initk "0"
:somef seq)
(eduction cat (remove (comp :bot :user)))
(run! update-member))
First time using iteration
. Seems to capture the semantics of pagination quite well.
discords api doesn’t return the last item id at the top level of the response, so you have to dive in and find it yourself by getting the last item. The only thing is that I’d probably always want to cat the results, feels like I’d expect that to be a part of the iteration api. But, other than that minor quirk (and I’m sure there’s a good reason for it) it’s much nicer than having to roll you’re own mechanism every time you deal with a third party api that’s paginated. @U050ECB92
if you're using https://discord.com/developers/docs/resources/guild#list-guild-members it looks like :initk
can be nil as the api param says the default is already '0'
ahh nice, currently it’s an empty vec, but I can move seq to that function then it make iteration even simpler to use. Have to say clojure getting functions for handling these core/common sorts of system abstractions is really nice.
#(-> % peek :user :id)
does peek work here? As it’s the id of the last item that I’d want to pass up to discord.
Ahh of course!
yeah I had some concerns with last
Completely forgot peek depends on the underlying collection.
What's the idiomatic way to run the same pieces of code over and over again until it does not raise an exception?
and a strategy to backoff -- I usually make a fn of a retry "epoch", that returns either a number of millis to sleep before the next retry, or nil, indicating cessation
(defn retry [op retry? backoff]
(loop [epoch 1]
(let [ret (op)]
(if-let [ms (and (retry? ret) (backoff epoch))]
(do (Thread/sleep ms)
(recur (inc epoch)))
ret))))
something like thishmm I was going to just do while (= ::failed (try ...
Here is an example from clj-kondo: https://github.com/clj-kondo/clj-kondo/blob/7a711ef748c401f3115e5a7823a7fa1b25125617/src/clj_kondo/impl/cache.clj#L66-L92
And one that I wrote: https://github.com/potetm/fusebox/blob/779e4a0dbe5b73e39e8386453590edfdbcd710df/src/clojure/com/potetm/fusebox.clj#L164-L264
(I wouldn’t use fusebox directly. I’m not doing anything with it. But you can feel free to rip whatever code you want out of there.)
Thank you all.
Is it possible to destructure strings with a slash using strs
?
(let [{:strs [foo/bar]} {"foo/bar" "quz"}] foo/bar)
> foo/bar - failed: simple-symbol? at: [:bindings :form :map-destructure :strs] spec: :clojure.core.specs.alpha/strs
> {:strs [foo/bar]} - failed: simple-symbol? at: [:bindings :form :local-symbol] spec: :clojure.core.specs.alpha/local-name
> {:strs [foo/bar]} - failed: vector? at: [:bindings :form :seq-destructure] spec: :clojure.core.specs.alpha/seq-binding-form
@U2PGHFU5U Although he could write
(let [{:keys [foo/bar]} (update-keys {"foo/bar" "quz"} keyword)]
bar)