[英]Ways of accessing nested map values in Clojure?
我目前正在使用以下兩個代碼塊來訪問ClojureScript中的嵌套值:
(def response (re-frame/subscribe [::subs/quote]))
(def body (:body @response))
(def value (:value body))
(println value)
(def result (-> @(re-frame/subscribe [::subs/quote]) :body :value))
(println result)
(def lol (get-in @(re-frame/subscribe [::subs/quote]) [:body :value]))
(println lol)
有沒有更好/更簡潔的方法? 謝謝。
可以將鍵用作操作符來檢索其值,如下所示:
(def lol (:value (:body @(re-frame/subscribe [::subs/quote]))))
(println lol)
不過,我更喜歡使用功能的詳細方式get-in
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.