Fork me on GitHub
#clojure
<
2022-01-08
>
SK09:01:46

hi! when you have a let with a long list of values, however some of the values cannot be calculated for some reason (eg some special situation like missing / invalid data), how can you "short circuit" the let and return some other value? An exception would work, but that I don't like, is there something better?

p-himik09:01:09

Yes, an if. You don't have to keep everything within the same let bindings vector - you can split it into multiple nested lets.

👍 1
vemv17:01:09

Maybe you can refactor things such that it's a reduce call and then you can use reduced

👍 1
vemv17:01:20

another short-circuity construct is some-> , although it's a bit more invasive (it forces you to use nil as the sentinel value)

SK21:01:44

@U2FRKM4TW @U45T93RA6 Yes I use both of these techniques, but I thought there is some more state-of-the-art 🙂 thanks to both of you

👍 2
didibus05:01:00

State of the art is throwing an exception I think 😛

didibus06:01:31

But I've seen https://github.com/adambard/failjure referred to a lot for these kind of scenarios. You could also use a macro, a let that checks if anything is reduced? and short-circuit returning the reduced value for example could work.

Benjamin09:01:56

I want my api to return a json with strong names out of instinct but my coworker requests small names. What do you usually do in that situation?

dreamer12:01:46

hello, I begin clojure. but I am not clojure envirment setting. please help me ( it is not brew install/clojure/tools/clojure/ I have Homebrew installed on my MacbookPro)

p-himik13:01:21

#beginners would be the perfect place.

dreamer05:01:12

oh, yes I am. thanks~

emccue17:01:50

Silly question, but where is the code for the clojure cli? I see a lot of the functionality in https://github.com/clojure/tools.deps.alpha but not the handling of CLI args like Stree, so i figure i am missing something

mkvlr18:01:00

@emccue I believe https://github.com/clojure/brew-install contains the code you're looking for

SK21:01:35

I'd like to change all the keywords in a map structure recursively. Does someone have an example spectre transform expression I can use as template? I've tried it like (transform [ALL MAP-KEYS] ...) but that did not work. Using (transform [MAP-KEYS] works, but not recursively)

p-himik21:01:43

I did this when I needed to process nested maps themselves. You can probably adapt it so it processes the keys instead of the maps. There should also be a helpful example or two in the Specter documentation.

(def MAP-NODES
  (s/recursive-path [] p
    (s/if-path map?
      (s/continue-then-stay s/MAP-VALS p)
      (s/if-path coll?
        [s/ALL p]))))

(defn transform-maps [^Map m f]
  (s/transform [MAP-NODES] f m))

👍 1
lilactown02:01:18

you might try clojure.walk if spectre isn't doing what you want

(clojure.walk/postwalk
 (fn [x]
   (if (map-entry? x)
     [(f (key x)) (val x)]
     x))
 data)

👍 1
1
SK11:01:29

thanks to both of you!