Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 478
Tim Visher Avatar asked Nov 29 '10 20:11

Tim Visher


2 Answers

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

{{:keys [width height]} :resolution}
like image 139
Arjan Avatar answered Nov 11 '22 19:11

Arjan


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

Works for me.

like image 31
Maurits Rijk Avatar answered Nov 11 '22 19:11

Maurits Rijk