Clojure applying a map and keyword arguments destruction

后端 未结 3 1884
生来不讨喜
生来不讨喜 2021-02-13 17:47

Consider a function with the following signature:

(defn make-widget [& {:keys [x y] :or {x 10 y 20}}]
 ...)

What is the best way to pass a

3条回答
  •  不思量自难忘°
    2021-02-13 18:03

    I can't think of a more elegant way, either, though it seems to me to that there should be one (like a map-specific variant of apply).

    Using flatten has problems beyond not being very elegant, though. If the values of your map are collections, flatten will work recursively on those, too, so things could get totally mixed up. This alternative avoids that problem:

    (apply make-widget (apply concat {:x 100}))
    

提交回复
热议问题