Pregunta

Tengo la siguiente estructura de datos:

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

Me gustaría escribir una función que desestructura la tecla :resolution en width y height símbolos. Algo así como

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

Es algo así es posible con la desestructuración?

Gracias.

¿Fue útil?

Solución

En primer lugar debe desestructuran: resolución, a continuación, obtener la anchura y altura:

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

Otros consejos

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

funciona para mí.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top