scgilardi / slingshot

Enhanced try and throw for Clojure leveraging Clojure's capabilities
654 stars 28 forks source link

Suppress 'and' clause in keyword catch clause. #54

Closed jbouwman closed 8 years ago

jbouwman commented 8 years ago

When only one keyword matching argument is present, it's not necessary to generate an 'and' container. There's no harm either, but linters such as 'eastwood' may complain.

Example:

(defn fun []
  (try+
   (something)
   (catch [:key :something] {}
     (recover))))

Macroexpansion before:

...
(contains? &throw-context :catch-hook-rethrow) (throw+)
(let [% (:object &throw-context)]
  (and (= (get % :key) :something))) (let
                                       [{}

After:

...
(contains? &throw-context :catch-hook-rethrow) (throw+)
(let [% (:object &throw-context)]
  (= (get % :key) :something)) (let
                                 [{}
scgilardi commented 8 years ago

Looks good, thank you! Can you please make a pull request into the master branch rather than the release branch? (There's an open feature request to allow editing this aspect of an open pull request, but it's not yet implemented.)

jbouwman commented 8 years ago

Sure! I'll open a new one.