Created
June 14, 2011 17:35
-
-
Save halfprogrammer/1025409 to your computer and use it in GitHub Desktop.
Keywords as function parameters in clojure?
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
(defn my-exists1? [lst obj & {:keys [testfn] :or {testfn =}}] | |
(when lst | |
(if (testfn (first lst) obj) | |
lst | |
(recur (next lst) obj testfn)))) | |
(my-exists1? '((1 2) (3 4) (5 6)) 3 :testfn #(= (first %1) %2)) | |
=> nil | |
(defn my-exists2? [lst obj testfn] | |
(when lst | |
(if (testfn (first lst) obj) | |
lst | |
(recur (next lst) obj testfn)))) | |
(my-exists2? '((1 2) (3 4) (5 6)) 3 #(= (first %1) %2)) | |
=> ((3 4) (5 6)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment