如何以类似于线程的方式在clojure中导航地图
在clojure中,有没有更好的方法浏览嵌套地图。例如,对于以下地图:如何以类似于线程的方式在clojure中导航地图,clojure,Clojure,在clojure中,有没有更好的方法浏览嵌套地图。例如,对于以下地图: { :one{ :two { :three value } } } 要获得:three的值,我需要(:three(:two(:one mymap)),但是如果有类似线程的东西,我可以在那里执行(>mymap:one:two:three)核心函数get-in正好满足您的需求,那就更好了 Returns the value in a nested associative structur
{
:one{
:two {
:three value
}
}
}
要获得
:three
的值,我需要(:three(:two(:one mymap))
,但是如果有类似线程的东西,我可以在那里执行(>mymap:one:two:three)
核心函数get-in正好满足您的需求,那就更好了
Returns the value in a nested associative structure,
where ks is a sequence of ke(ys. Returns nil if the key is not present,
or the not-found value if supplied.
(get-in your-nested-data [:one :two :three])
“如果有类似线程的东西,我可以在那里做(>mymap:1:2:3)
”
谁说你不能?你的确切语法有效
so.core=> (def mymap { :one, { :two, { :three :value } } })
#'so.core/mymap
so.core=> (-> mymap :one :two :three)
:value
顺便说一句,你的线程示例不仅可以这样工作,而且
(clojure.walk/macroexpand-all'(>mymap:one:two:three))
给出了原始的(:three(:two(:one mymap)))
语法!抱歉在我问这个问题之前没有试过!至少其他人可能会觉得这个页面很有帮助,因为我在谷歌上找不到任何东西,这就是我问的原因。