reagent

DeepReef11 2023-08-02T00:55:03.795039Z

What's wrong with the following?

(def months-name ["Jan"
                 "Feb"
                 "Mar"
                 "Apr"
                 "May"
                 "Jun"
                 "Jul"
                 "Aug"
                 "Sep"
                 "Oct"
                 "Nov"
                 "Dec"
                  ])
(defn []
  [:div (mapv (fn [x] [:div  x ]) months-name)])
Do I need to do the mapv outside of the div and put the result there? It says invalid arity

DeepReef11 2023-08-02T13:38:30.607529Z

What's invalid about (defn [] ...) ?

DeepReef11 2023-08-02T14:02:51.270719Z

I was able to make the for work, but the mapv won't

DeepReef11 2023-08-02T14:03:02.071519Z

Why is that?

thheller 2023-08-02T14:44:25.629209Z

impossible to comment without seeing what your actual code was

thheller 2023-08-02T14:45:56.758059Z

but in general you need to consider what the final result is. so for example with mapv you end up with [:div [[:div "Jan"] [:div "Feb"]] which reagent might not like, the for produces a lazy-seq which reagent probably handles in special ways

DeepReef11 2023-08-02T15:17:19.583089Z

I see! Is there a way to make a sequence return as its content?

thheller 2023-08-02T15:20:24.204119Z

(into [:div] (mapv ...)) is an option

✅ 1
DeepReef11 2023-08-02T15:23:16.311279Z

Great it works, thanks a lot!

hifumi123 2023-08-02T01:39:47.805669Z

The idiom in reagent is usually to write something like this

(def months ["January" "Feburary" "March" "..."])

(defn panel []
  (into [:div] (for [month months]
                 [:div {:key month} month])))

hifumi123 2023-08-02T01:53:26.769229Z

Replacing the divs with an unordered list, we get the following result

thheller 2023-08-02T06:26:13.292269Z

you need to share your actual code if you want accurate help. (defn [] ...) is invalid

thheller 2023-08-02T06:27:03.245929Z

you could have (mapv (fn [x] ...)) months-name which would give you a invalid arity? ie a misplaced )