Created
November 5, 2012 10:05
-
-
Save sarahhodne/4016434 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(ns leonardo.users) | |
(defn init-users | |
[] {}) | |
(defn add-user | |
[users username] | |
(conj users | |
{username | |
{:points 0 | |
:reasons {}}})) | |
(defn get-points | |
[users username] | |
(:points (users username))) | |
(defn set-points | |
[users username points] | |
(assoc-in users [username :points] points)) | |
(defn incr-points | |
[users username delta] | |
(update-in users [username :points] + delta)) | |
(defn- create-reason | |
[users username reason] | |
(if (reason (:reasons (users username))) | |
users | |
(assoc-in users [username :reasons reason] 0))) | |
(defn incr-reason | |
[users username reason] | |
(update-in (create-reason users username reason) | |
[username :reasons reason] inc)) | |
(defn reason-count | |
[users username reason] | |
(reason (:reasons (users username)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment