-
-
Save miikka/ed0106b8b8a99a710cd2dd65e02b0b34 to your computer and use it in GitHub Desktop.
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
(ns foo.core) | |
(defmacro | |
fn+ | |
"Destructure params marked with ^js as JavaScript objects." | |
[args & body] | |
(let [js-map (into {} (for [x args :when (= (:tag (meta x)) 'js)] | |
[x (gensym)])) | |
js-args (into [] (for [x args] (get js-map x x))) | |
dst (into [] (apply concat (for [[x n] js-map] `[~x (js->clj ~n)])))] | |
`(fn ~js-args (let ~dst ~@body)))) | |
;; => (def a-plus-b (fn+ [^js {:strs [a b]}] (+ a b))) | |
;; #'cljs.user/a-plus-b | |
;; => (a-plus-b #js {:a 1 :b 2}) | |
;; 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment