Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Vague attempt to tidy up nil-safe

  • Loading branch information...
commit 71f8f5b22b5080794602342e9e2879bfa61d0231 1 parent 5ff6a80
Alan Malloy authored
Showing with 7 additions and 5 deletions.
  1. +7 −5 modules/core/src/main/clojure/clojure/contrib/core.clj
12 modules/core/src/main/clojure/clojure/contrib/core.clj
View
@@ -21,11 +21,13 @@
(defmacro- defnilsafe [docstring non-safe-name nil-safe-name]
`(defmacro ~nil-safe-name ~docstring
- {:arglists '([~'x ~'form] [~'x ~'form ~'& ~'forms])}
- ([x# form#]
- `(let [~'i# ~x#] (when-not (nil? ~'i#) (~'~non-safe-name ~'i# ~form#))))
- ([x# form# & more#]
- `(~'~nil-safe-name (~'~nil-safe-name ~x# ~form#) ~@more#))))
+ {:arglists '~'([x form] [x form & forms])}
+ ([x# form#]
+ (let [n# #'~non-safe-name]
+ `(let [~'i# ~x#] (when-not (nil? ~'i#) (~n# ~'i# ~form#)))))
+ ([x# form# & more#]
+ (let [n# #'~nil-safe-name]
+ `(~n# (~n# ~x# ~form#) ~@more#)))))
(defnilsafe
"Same as clojure.core/-> but returns nil as soon as the threaded value is nil itself (thus short-circuiting any pending computation).
Please sign in to comment.
Something went wrong with that request. Please try again.