Strategy pattern in Clojure

less than 1 minute read

Notes

cljuser>  ; Use `alt+enter` to evaluate
;; strategy pattern

(+ 4 3)
7

cljuser> 
(*  4 3)
12

cljuser> 
((if true + *) 4 3)
7

cljuser> 
((if false + *) 4 3)
12

cljuser> 
(defn add [a b] (+ a b))
#'user/add

cljuser> 
(defn multiply [a b ] (* a b))
#'user/multiply


cljuser> 
((if false add multiply) 4 3)
12

cljuser> 
((if true add multiply) 4 3)
7

Updated: