开发者

Destructure a map in another map?

I have the following data structure:

{:file #<File /foo.bar>, :resolution {:width 1280, :height 1024}}
开发者_开发问答

I would like to write a function that destructures the :resolution key into width and height symbols. Something like

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

Is something like that possible with destructuring?

Thanks.


You must first destructure :resolution, then get width and height:

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


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

Works for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜