This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-13
Channels
- # babashka (7)
- # babashka-sci-dev (3)
- # beginners (29)
- # biff (16)
- # calva (2)
- # clojars (1)
- # clojure (50)
- # clojure-austin (5)
- # clojure-europe (29)
- # clojure-france (8)
- # clojure-nl (3)
- # clojure-uk (3)
- # clojured (10)
- # clojurescript (18)
- # code-reviews (3)
- # core-async (22)
- # cursive (5)
- # data-science (11)
- # datalevin (1)
- # datomic (10)
- # eastwood (4)
- # helix (4)
- # introduce-yourself (2)
- # jobs (1)
- # jobs-discuss (1)
- # joyride (6)
- # leiningen (4)
- # london-clojurians (2)
- # lsp (82)
- # malli (7)
- # meander (12)
- # minecraft (3)
- # nbb (14)
- # off-topic (52)
- # podcasts (3)
- # portal (3)
- # re-frame (32)
- # reagent (9)
- # releases (2)
- # shadow-cljs (95)
- # tools-deps (14)
(read-string (prn-str (java.time.Instant/now)))
how do I do this correctly? Printing and reading timestamps, or other objects for that matter (guess it has something to do with reader tags)the source is tiny, I found it incredibly helpful to see how to implement data reader literals
Hey! Looking for feedback on a problem - wondering if there's an idiomatic solution I'm not seeing. I have a set of sources to get some data from. I want to try the sources in sequence, and find the first source that made sense. If that was the whole problem, I could do:
(or (source1) (source2) (source3))
.
But I don't want to return just the return value from the function. I also want to tag where it came from! With a cond, it could look like this:
(cond
(source1) [(source1) :source1]
(source2) [(source2) :source2]
(source3) [(source3) :source3])
Two problems with that solution:
• (sourcex)
is repeated in code.
• We call (sourcex)
twice - meaning we hit the network twice, which is unnecessary.
---
How would you solve this?"real problem" here: https://github.com/babashka/neil/pull/45
Alternative:
(or
(when-let [s (source1)] [s :source1])
(when-let [s (source2)] [s :source2])
(when-let [s (source3)] [s :source3]))
Or alternatively
1. Execute all of them in parallell
2. drop-while
first element of tuple is nil.
have you ever seen the demo that got used to demonstrate channels when golang was first released?
perhaps:
(->> [[:source1 source1] [:source2 source2] [:source3 source3]]
(pmap (fn [kw action & args]
[kw (apply action args)]))
(keep second)
second)
still way more code than the very simple (or (source1) (source2) (source3))
.but the scenario is something like "you need to render google search results, the results come from N backend servers, fan out and only render results that don't timeout"
it intermingles concurrent execution and lazy seq construction in a way that can be surprising, and doesn't expose the knobs I would want for controlling the parallel execution
hmm. Yeah, I guess I'd be stuck once I needed something like timeouts. I haven't really had the chance to get properly into core.async or similar libraries / ways of thinking.
core.async is not strictly required, but it will make it possible to do a pretty direct translation of the golang example
How did we get from "I want to try the sources in sequence..." to discussions of trying sources in parallel? Those are two different specs altogether.
from https://github.com/matthiasn/talk-transcripts/blob/master/Hickey_Rich/CoreAsync.md
I'm guessing your question wasn't about parallelizing those. In that case, you can do:
(some second [[:source1 (source1)] [:source2 (source2)] [:source3 (source3)]])
Though... might need to think about the behavior with side-effects, not sure if it'll be chunked.
Otherwise I would get too hung up on it and use your or with when-let combo or just use nested if-let