Last active
May 25, 2021 15:14
-
-
Save rauhs/d49d6f8a6f5fbb8230647c5b2ac210b2 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
(defmacro afor | |
"Like for but eagerly builds a JS array. | |
Usually for react consumption." | |
[[item coll] & body] | |
`(reduce (fn [neue# ~item] | |
(.push neue# (do ~@body)) | |
neue#) | |
(cljs.core/array) ~coll)) | |
(defmacro arfor | |
"Like for but eagerly builds a JS array. | |
Usually for react consumption." | |
[[item coll] & body] | |
`(reduce (fn [neue# ~item] | |
(.push neue# (html ~@body)) | |
neue#) | |
(cljs.core/array) ~coll)) | |
(defmacro arifor | |
"Like arfor also gives the index. Syntax is like this to allow cursive to give variable | |
highlighting. Note: not destructing is happening. A fast reduce with an index is done. | |
(arifor [[idx item] items] | |
[:div {} idx \":\" item])" | |
[[[idx item] coll] & body] | |
`(let [coll# ~coll | |
neue# (cljs.core/array)] | |
(reduce (fn [~idx ~item] | |
(.push neue# (html ~@body)) | |
(inc ~idx)) | |
0 coll#) | |
neue#)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will need a
html
macro which can be like: