Fork me on GitHub

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?


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

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

👍 1

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


@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

State of the art is throwing an exception I think 😛


But I've seen 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.


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?


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)


#beginners would be the perfect place.


oh, yes I am. thanks~


Silly question, but where is the code for the clojure cli? I see a lot of the functionality in but not the handling of CLI args like Stree, so i figure i am missing something


@emccue I believe contains the code you're looking for


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)


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.

  (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

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

 (fn [x]
   (if (map-entry? x)
     [(f (key x)) (val x)]

👍 1

thanks to both of you!