[英]Ways of accessing nested map values in Clojure?
I am currently using the two following blocks of code to access nested values in ClojureScript: 我目前正在使用以下两个代码块来访问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)
Are there any better / more succinct ways of doing this? 有没有更好/更简洁的方法? Thanks.
谢谢。
Keys can be used as operators to retrieve its value like so: 可以将键用作操作符来检索其值,如下所示:
(def lol (:value (:body @(re-frame/subscribe [::subs/quote]))))
(println lol)
However, I prefer the verbose way using a function as get-in
不过,我更喜欢使用功能的详细方式
get-in
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.