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

Tim*_*her 16 clojure destructuring

我有以下数据结构:

{:file #<File /foo.bar>, :resolution {:width 1280, :height 1024}}
Run Code Online (Sandbox Code Playgroud)

我想编写destructures的功能:resolution键进入widthheight符号.就像是

(defn to-directory-name [{{:keys [width height]}} wallpaper]
  (str width "x" height))
Run Code Online (Sandbox Code Playgroud)

这种可能与解构有关吗?

谢谢.

Arj*_*jan 19

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

{{:keys [width height]} :resolution}
Run Code Online (Sandbox Code Playgroud)

  • 只需将它们放在同一个`{}`:`{{:keys [ab]}:query-params {:keys [cd]}:path-params}` (2认同)

Mau*_*ijk 5

(defn to-directory-name [{{width :width height :height} :resolution}] 
  (str width "x" height))
Run Code Online (Sandbox Code Playgroud)

为我工作。