سؤال

لدي بنية البيانات التالية:

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

أود أن أكتب وظيفة تدمر :resolution مفتاح في width و height حرف او رمز. شيء مثل

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

هل شيء من هذا القبيل ممكن مع التدمير؟

شكرًا.

هل كانت مفيدة؟

المحلول

يجب عليك أولاً التدمير: القرار ، ثم الحصول على العرض والارتفاع:

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

نصائح أخرى

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

يعمل لدي.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top