Skip to content

Instantly share code, notes, and snippets.

@alexanderjamesking
Last active April 28, 2018 11:35
Show Gist options
  • Save alexanderjamesking/f204ae13ad9db4983cf58f0d01c88e0f to your computer and use it in GitHub Desktop.
Save alexanderjamesking/f204ae13ad9db4983cf58f0d01c88e0f to your computer and use it in GitHub Desktop.
(require '[clojure.test :refer [is]])
(defn random-beatle []
(case (rand-int 4)
0 "John"
1 "Paul"
2 "George"
3 "Ringo"))
(defn hello-beatle [get-beatle]
(str "Hello " (get-beatle)))
;; pass in a stub
(is (= "Hello George" (hello-beatle (fn [] "George"))))
;; or use constantly to create a stub
(is (= "Hello George" (hello-beatle (constantly "George"))))
;; we can use this to build a new function
(defn hello-random-beatle []
(hello-beatle random-beatle))
;; or we can use partial to create a new function
(def hello-random-beatle (partial hello-beatle random-beatle))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment