Fork me on GitHub
#clojure-uk
<
2021-04-19
>
dharrigan06:04:58

Good Morning!

dharrigan08:04:54

I was a bit surprised to learn that destructuring a map, that has a nil, using either when-some or when-let doesn't do what I thought it might do

dharrigan08:04:25

(def config {:foo {:bar nil}})

(when-some [{{:keys [bar]} :foo} config]
  (format "This is %s" bar)) ;; "This is null"

dharrigan08:04:06

The doc's say that when-some will only evaluate the body if the test is not nil.

mccraigmccraig08:04:08

the test is the whole bound value @dharrigan, not something destructured out of it - and config is not nil

dharrigan08:04:36

that makes sense, yup. still, had to learn that 🙂

dharrigan08:04:06

so is there a better way of writing this so that if "bar" is nil, then not to execute the body?

dharrigan08:04:28

I was thinking of just testing again i.e., a nested (when bar ,,,,,)

mccraigmccraig08:04:31

that's what i would do

dharrigan08:04:41

:thumbsup: that's what I did 🙂

folcon08:04:57

Have people seen this by any chance? https://github.com/IGJoshua/farolero

dharrigan08:04:15

I was reading about it this weekend, prompted by the blog posting

folcon08:04:11

I've not used CL style exceptions much, but they seem handy, I'm assuming they handle normal js / java exceptions as well, would be cool to see some more interesting things happening here 😃...

folcon08:04:46

Can you link the blog post? I don't think I've seen it...

dharrigan08:04:45

My current understanding, and I believe something the blog author also comments upon, is that because (at least on the JVM) Clojure, being a hosted language, the normal paradigms of try, catch and if-some (and the ilk) are very common, then it may feel a bit unnatural

dharrigan08:04:30

I'm not sure tbh, I will definitely need to spend some more time experimenting and learning to see if it works for me 😉

dharrigan08:04:05

Here's the blog post btw:

folcon08:04:06

Thanks 😃... I mean I'm hoping it will allow for more flexibility in dealing with exceptions...

dharrigan08:04:00

Yes, agreed. I am eager to delve further into it and see if can help my applications 🙂