I'm using hiccup to generate some checkboxes followed by labels. The original code looked like this:
(check-box "check1")
(label "check1" "Check1")
(check-box "check2")
(label "check2" "Check2")
(check-box "check1")
(label "check3" "Check3")
(check-box "check4")
(label "check4" "Check4")
Which, after a lot of tinkering, I got down to the following line:
(map
(fn [x]
(map
#(get (vector
(check-box x)
(label x (capitalize x)))%)
[0 1]))
["check1" "check2" "check3" "check4"])
Which works, but I feel I'm not doing it in a very lisp-like/optimized/correct/etc. way - especially returning a vector just to scoop out those values with get. Is there a better way to do this?
Perhaps destructuring is what you need?
(defn multi-return-fn []
[:1 :2 :3])
(let [[x y z] (multi-return-fn)]
(println x)
(println y)
(println z))
Destructuring also works in fn arguments, loop, for loops, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With