Skip to content

Instantly share code, notes, and snippets.

@djwonk
Forked from anonymous/example_of_atom_swap.clj
Last active December 10, 2015 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djwonk/4471934 to your computer and use it in GitHub Desktop.
Save djwonk/4471934 to your computer and use it in GitHub Desktop.
(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