Fork me on GitHub
M J11:02:47

Hello, I want to change an atom only when another atom changes value, ho wdo I do that? For example, I have a value

(let [button-disabled? (r/atom true)])
I also have children that are
(let [email-button-disabled? (r/atom true)
      number-button-disabled? (r/atom true)])
When one of them turns false, I want to change the main one.

M J13:02:18

Thanks! 🙏


it looks like those are not normal Clojure atoms but atoms from reagent library. if that is the case then look at reactions provided by reagent


also there is #C0620C0C8 channel

Sam Ritchie16:02:15

Add-watch will work too I believe! But reactions are nice of course


Hello y’all, thanks for the amazing help last time! I’ve been banging my head against a sort problem regarding a vector of maps and maybe someone is able to point me into the right direction. I have following structure:

[{:score 22/111, :size 2}
 {:score 8/113, :size 3}
 {:score 200/221, :size 19}
 {:score 8/113, :size 6}
 {:score 2/3, :size 20}
 {:score 1N, :size 3}
 {:score 0, :size 2}]
I now want to sort this by score descending and by size ascending like this:
[{:score 1N, :size 3}
 {:score 200/221, :size 19}
 {:score 2/3, :size 20}
 {:score 22/111, :size 2}
 {:score 8/113, :size 3}
 {:score 8/113, :size 6}
 {:score 0, :size 2}]
I already tried to wrap my head around the sort-by, group-by and min/max-key functions, but I wasn’t able to find the correct way to combine these for the desired result. I’m grateful for any help and/or push in the right direction 🙂

Martin Půda18:02:41

(->> data
     (sort-by (juxt #(- (:score %)) :size)))

Ben Sless18:02:46

Does it help knowing sequences are sorted lexicographically? [1 2] > [1 1]


Thanks for the answers, the link to writing your own comparators is especially helpful!

simple_smile 1