Single-value atom update

I have the number of atoms in my code, where the general requirement is to update them to a new value, regardless of the current value.

Therefore, I believe that I am writing something like this:

(swap! atom-name (fn [_] (identity new-value)))

This works, but it seems pretty ugly and seems to carry a fine for doing an anonymous closure.

Is there a better way?

+5
source share
2 answers

The function reset!should do this.

(reset! atom-name new-value)
+8
source

You can use (compare and set a new value for a new atom value).

But it seems strange to me that you need to change them so much to uncorrelated values. You cannot use bindings or similar things.

+1

All Articles