Updating an atom with a single value

Posted by mikera on Stack Overflow See other posts from Stack Overflow or by mikera
Published on 2010-06-17T23:21:35Z Indexed on 2010/06/17 23:33 UTC
Read the original article Hit count: 218

Filed under:
|
|

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

I therefore find myself writing something like this:

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

This works but seems pretty ugly and presumably incurs a performance penalty for constructing the anonymous closure.

Is there a better way?

© Stack Overflow or respective owner

Related posts about concurrency

Related posts about clojure