Last active
April 28, 2018 11:35
-
-
Save alexanderjamesking/f204ae13ad9db4983cf58f0d01c88e0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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