Skip to content

Instantly share code, notes, and snippets.

@hadielmougy
hadielmougy / atomic_state_update.clj
Created November 25, 2017 19:26 — forked from stuarthalloway/atomic_state_update.clj
Update state with a pure function
;; fixed version of 'state' at http://mishadoff.com/blog/clojure-design-patterns/#episode-3-state
;; takeaway: if you call 'swap!' twice on the same atom, you are probably making a mistake
(def user {:name "Jackie Brown"
:balance 0
:subscription? false})
(def ^:const SUBSCRIPTION_COST 30)
(defn pay
@hadielmougy
hadielmougy / gist:5d468409e2e5d75e1f33fba92cca721b
Created March 23, 2017 14:40 — forked from dekellum/gist:4171049
powerset in clojure using sets,union
(ns powerset.core-test
(:use (clojure set test)))
(defn powerset [s]
(apply union
#{s} ;the complete set of all s
(map (fn [i] (powerset (disj s i))) s)))
(deftest test-powerset
(is (= #{#{}}