Skip to content

Instantly share code, notes, and snippets.

@sarahhodne
Created November 5, 2012 10:05
Show Gist options
  • Save sarahhodne/4016434 to your computer and use it in GitHub Desktop.
Save sarahhodne/4016434 to your computer and use it in GitHub Desktop.
(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