Skip to content

Instantly share code, notes, and snippets.

@halfprogrammer
Created June 14, 2011 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save halfprogrammer/1025409 to your computer and use it in GitHub Desktop.
Save halfprogrammer/1025409 to your computer and use it in GitHub Desktop.
Keywords as function parameters in clojure?
(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