Fork me on GitHub
#beginners
<
2021-04-25
>
Oliver06:04:54

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.

Ben Sless07:04:43

desktop? web app? CLI?

Oliver07:04:44

Web app would be the target, but I am happy to start with some simple desktop apps if that is easier to start.

Ben Sless09:04:27

Web app would be easier, actually, take a look at https://github.com/seancorfield/usermanager-example/

πŸ™ 3
Eric Ihli12:04:38

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.

kennytilton13:04:13

Just inherited ` (some->> (get-in db [:hi :mom]) (into [])) Curious about (into []). Why not just a literal []? Thx!

Stuart13:04:53

(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?

yuhan13:04:43

I usually use vec for this, but (into []) might communicate the intent clearer.

athomasoriginal15:04:55

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)

Lukas17:04:33

Hello, could anyone help me with the following: how do I realize a lazy seq and spit it into a edn file?

Lukas17:04:35

Nvm my bad I was looking into the wrong file πŸ™ˆ πŸ˜‚ I'm sorry

sova-soars-the-sora17:04:16

if you change a lot of code multiple times and nothing changes... maybe it is a different file xD ... hard-won lessons of coding

❀️ 4
andy.fingerhut18:04:11

The nice thing of that advice is that it is independent of programming language πŸ™‚

πŸ˜† 2
piyer20:04:27

I am trying to find a nice linter. I currently use eastwood and kibit, what do people generally use?

dharrigan20:04:33

clj-kondo #clj-kondo

piyer20:04:58

will check it out. I was expecting eastwood to throw errors for unused imports

piyer20:04:03

It did not.

dharrigan20:04:17

clj-kondo will flag unused imports

Daniel Basner20:04:38

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 value

hiredman21:04:52

Well, db is never updated

hiredman21:04:04

db is a name bound to an immutable value

Daniel Basner21:04:15

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

Daniel Basner21:04:11

kind of like a combo between cond-> and as-> where you can thread the updated value through any position(s) you want

hiredman21:04:18

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

Daniel Basner21:04:37

thanks! I will take a look

seancorfield21:04:18

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.

seancorfield21:04:00

(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?

Daniel Basner21:04:44

yeah, thanks! example is super helpful

seancorfield21:04:39

$ 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

piyer22:04:07

with-open with a custom closing problem looks generic enough that I am expecting something pre-written.

andy.fingerhut23:04:05

Maybe in a 3rd party library (not one I know about, unfortunately), but I don't think such a thing is built in.

andy.fingerhut23:04:26

You could use something like proxy to create a one-off object with a close method that calls your custom close method.

andy.fingerhut23:04:34

and use built-in with-open on that object.

andy.fingerhut23:04:11

I haven't done this before, so may be getting confused over whether proxy, reify, or something similar is the best choice here.

piyer00:04:15

that is a good idea.

piyer00:04:20

will try that.