Last active
January 19, 2021 14:16
-
-
Save fogus/119adfe60951e36ad38a5f1d35c4ea80 to your computer and use it in GitHub Desktop.
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
| ;; Basis | |
| (fn [& {:keys [a b]}] (+ a b)) | |
| ;; gen param lists approach | |
| (defn param-gen-style | |
| ([a-map] | |
| (let [{:keys [a b]} a-map] | |
| (+ a b))) | |
| ([a-key a-val & kvs] | |
| (let [{:keys [a b]} (concat (list a-key a-val) kvs)] | |
| (+ a b)))) | |
| (param-gen-style {:a 1 :b 2}) | |
| ;;=> 3 | |
| (param-gen-style :a 1 :b 2) | |
| ;;=> 3 | |
| ;; gen map check approach | |
| (defn map-check-style | |
| [& kvs] | |
| (let [maybe-map (if (map? (first kvs)) (first kvs) kvs) | |
| {:keys [a b]} maybe-map] | |
| (+ a b))) | |
| (map-check-style {:a 1 :b 2}) | |
| ;;=> 3 | |
| (map-check-style :a 1 :b 2) | |
| ;;=> 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment