Hi Everybody,
Could you please tell me is there a rule of thumb for creating functions with varying number of arguments? Like this:
(defn fun-with-fn [& args]
(str "I have seqable " (seqable? args) ": " args))
and then using it
(fun-with-fn 1 2 3)
;; => "I have seqable true: (1 2 3)"
or
(apply fun-with-fn [1 2 3])
;; => "I have seqable true: (1 2 3)"
or just create a function that works with sequences?
(defn fun-with-fn2 [args]
(str "I have another seqable " (seqable? args) ": " args))
(fun-with-fn2 [1 2 3])
;; => "I have another seqable true: [1 2 3]"
My understanding is that varying number of arguments is nicer for people since (+ 1 2 3)
looks better than (+ [1 2 3])
but for example (clojure.string/join ["a" "b" "c"])
takes sequence instead of (join "a" "b" "c")
so I don’t know…
Could you please tell me when should I prefer sequence / when to use varargs?
Thank you.
Matys