Skip to content

Instantly share code, notes, and snippets.

@jackcallister
Created May 2, 2020 00:14
Show Gist options
  • Save jackcallister/98a1a95444bc7220fc07fdcec913aab8 to your computer and use it in GitHub Desktop.
Save jackcallister/98a1a95444bc7220fc07fdcec913aab8 to your computer and use it in GitHub Desktop.
(ns bank-account)
(defn open-account []
(atom 0)
)
(defn close-account [account]
(reset! account nil)
)
(defn is-open? [account]
(not (nil? @account)))
(defn get-balance [account]
@account
)
(defn update-balance [account amount]
{ :pre [(is-open? account)] }
(swap! account (fn [v] (+ v amount)))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment