在另一张地图中构建地图?

时间:2010-11-29 20:32:33

标签: clojure destructuring

我有以下数据结构:

{:file #<File /foo.bar>, :resolution {:width 1280, :height 1024}}

我想编写一个将:resolution密钥解构为widthheight符号的函数。像

这样的东西
(defn to-directory-name [{{:keys [width height]}} wallpaper]
  (str width "x" height))

这种类似的东西可能会被解构吗?

感谢。

2 个答案:

答案 0 :(得分:18)

你必须首先解构:分辨率,然后获得宽度和高度:

{{:keys [width height]} :resolution}

答案 1 :(得分:4)

(defn to-directory-name [{{width :width height :height} :resolution}] 
  (str width "x" height))

适合我。

相关问题