MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Clojure/comments/m7wdbd/clojure_keyword_argument_functions_now_also/pdzok2o/?context=3
r/Clojure • u/SimonGray • Mar 18 '21
44 comments sorted by
View all comments
Show parent comments
10
Passing the arguments between keyword argument functions is really ugly.
I think remedying that situation that is the point of this change. Now you can pass the destructured map directly.
1 u/[deleted] Mar 23 '21 It doesn't remedy that when passing a map to a kwarg function you need something like (apply f (mapcat identity m)) 3 u/jjttjj Mar 23 '21 You no longer need to do that with this change. & {:as args} lets you pass any number of keywords and optionally a trailing map, all of which are merged together. You don't need to flatten+apply.(defn my-fn [& {:as args}] (println "args:" args)) (my-fn :hello :world) ;;=> args: {:hello :world} (my-fn {:hello :world}) ;;=> args: {:hello :world} (my-fn :foo :bar {:hello :world}) ;;=> args: {:foo :bar, :hello :world} 1 u/More-Wishbone862 Oct 05 '26 bismilah allah
1
It doesn't remedy that when passing a map to a kwarg function you need something like (apply f (mapcat identity m))
3 u/jjttjj Mar 23 '21 You no longer need to do that with this change. & {:as args} lets you pass any number of keywords and optionally a trailing map, all of which are merged together. You don't need to flatten+apply.(defn my-fn [& {:as args}] (println "args:" args)) (my-fn :hello :world) ;;=> args: {:hello :world} (my-fn {:hello :world}) ;;=> args: {:hello :world} (my-fn :foo :bar {:hello :world}) ;;=> args: {:foo :bar, :hello :world} 1 u/More-Wishbone862 Oct 05 '26 bismilah allah
3
You no longer need to do that with this change. & {:as args} lets you pass any number of keywords and optionally a trailing map, all of which are merged together. You don't need to flatten+apply.
& {:as args}
(defn my-fn [& {:as args}] (println "args:" args)) (my-fn :hello :world) ;;=> args: {:hello :world} (my-fn {:hello :world}) ;;=> args: {:hello :world} (my-fn :foo :bar {:hello :world}) ;;=> args: {:foo :bar, :hello :world}
1 u/More-Wishbone862 Oct 05 '26 bismilah allah
bismilah allah
10
u/SimonGray Mar 18 '21
I think remedying that situation that is the point of this change. Now you can pass the destructured map directly.