Created
May 11, 2015 08:48
-
-
Save pesterhazy/e191d0157b6f5cfe2ed8 to your computer and use it in GitHub Desktop.
when-seq: conditionally apply operation on sequence in threading macro
This file contains 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 when-seq | |
"If condition is true, perform seq operation f on xs with args; otherwise return f. | |
Intended for use in the thread first macro. For example: | |
(-> [] | |
(when-seq x conj x)) | |
will be [:foo] if x is :foo, [] if x is nil" | |
[xs condition f & args] | |
(if condition | |
(apply f xs args) | |
xs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
clojure.core/cond->
is probably more useful