Forked from anonymous/example_of_atom_swap.clj
Last active
December 10, 2015 18:08
-
-
Save djwonk/4471934 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def players | |
[{:id 1 :health 100} {:id 2 :health 90}]) | |
(def game | |
{:players players}) | |
(def current-game | |
(atom game)) | |
(defn kill-player | |
[player] | |
(assoc player :health 0)) | |
(defn kill-players | |
[players] | |
(map kill-player players)) | |
(defn kill-players! | |
[game-atom] | |
(swap! game-atom update-in [:players] kill-players)) | |
(kill-players! current-game) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment