Any recommendations for good reads how to build a (simple) application with Clojure? I understand the basics for data manipulation, but I struggle with control flow, user interface and working with immutability in practice.
desktop? web app? CLI?
Web app would be the target, but I am happy to start with some simple desktop apps if that is easier to start.
Web app would be easier, actually, take a look at https://github.com/seancorfield/usermanager-example/
This may be of interest too https://practicalli.github.io/clojure-webapps/
Are there any gotchas or concerns about putting side-effects in a transduction? I searched and found https://groups.google.com/g/clojure/c/SVaFtQgtolc and my understanding is that what the original asker is doing should be fine since transduce/reduce is non-lazy. But the first line of the answer that says "Transducers are a new feature and best practices are still emerging" make me wonder if the best practice that has emerged may be that it's a bad idea for some reason.
Just inherited `
(some->> (get-in db [:hi :mom])
(into []))
Curious about
(into [])
. Why not just a literal []
? Thx!
(let [res '(:a :b :c)]
(into [] res))
=> [:a :b :c]
(let [res '(:a :b :c)]
[res])
=> [(:a :b :c)]
With the literal []
you won't get the conj
type behaviour, so you will end up with a nested collection?I usually use vec
for this, but (into [])
might communicate the intent clearer.
I have a ring-jetty server. I use 3rd party libraries in my server which make network requests (think stripe sdk). I would like to monitor the network requests my server is making. What do people like to do for this? I use Charles Proxy to monitor front end requests, but iβm not sure if this tool is also used for monitor requests my server makes :thinking_face: (apologies if there is a better channel for this post as I know itβs not really Clojure specific)
Hello, could anyone help me with the following: how do I realize a lazy seq and spit it into a edn file?
Nvm my bad I was looking into the wrong file π π I'm sorry
if you change a lot of code multiple times and nothing changes... maybe it is a different file xD ... hard-won lessons of coding
The nice thing of that advice is that it is independent of programming language π
I am trying to find a nice linter. I currently use eastwood and kibit, what do people generally use?
I also saw https://github.com/candid82/joker
clj-kondo
#clj-kondo
is there a way to use the value being threaded in cond->
in the condition used to decide whether or not to call the associated fn? if you do
(cond-> db
true (something-that-changes-db)
(some-cond? db) (called-conditionally))
the value used in that condition seems to be the original db, not the newly updated db valuewill check it out. I was expecting eastwood to throw errors for unused imports
It did not.
clj-kondo will flag unused imports
perfect
Well, db is never updated
db is a name bound to an immutable value
yeah, it makes sense that the above does not work, having looked at it, but I was wondering how I could use the updated value in that next cond
kind of like a combo between cond->
and as->
where you can thread the updated value through any position(s) you want
There is nothing built it for it, but various libraries add their own macros that do that sort thing like https://github.com/worldsingles/commons/blob/master/src/ws/clojure/extensions.clj#L50
thanks! I will take a look
The thing to watch with condp->
is that all of the conditions must be predicate expressions: you start with cond-> db true ...
so that true
needs to be something that db
can be threaded into and will yield true
.
(condp-> db (or true) (something-that-changes) (some-cond?) (called-conditionally))
might be what you need: db
is threaded as the first argument into the first condition and (if truthy) the first result expression, and the result of that will be threaded into (some-cond?)
and if that's truthy, it'll be threaded into (called-conditionally)
-- make sense?
$ clj -Sdeps '{:deps {worldsingles/ws-commons {:mvn/version "RELEASE"}}}'
Downloading: worldsingles/ws-commons/maven-metadata.xml from clojars
Clojure 1.10.3
worldsingles/clojure/extensions.cljc on classpath.
user=> (require '[ws.clojure.extensions :refer :all])
nil
user=> (condp-> 42 (or true) (inc) (odd?) (inc))
44
user=> (condp-> 42 (or true) (inc) (even?) (inc))
43
yeah, thanks! example is super helpful
with-open
with a custom closing problem looks generic enough that I am expecting something pre-written.
Maybe in a 3rd party library (not one I know about, unfortunately), but I don't think such a thing is built in.
You could use something like proxy
to create a one-off object with a close
method that calls your custom close method.
and use built-in with-open
on that object.
I haven't done this before, so may be getting confused over whether proxy
, reify
, or something similar is the best choice here.