嵌套的地图矢量如何获取值

时间:2014-02-07 11:22:37

标签: clojure

{:measure-value-sets (
   {:benchmark "EUR.EONIA.6Y", :bvalue "0"}),
 :dimensions (
   {:type "Currency", :dvalue "EUR"} 
   {:type "ValueUnderlying_0", :dvalue "21.59999999999811"})}

{:measure-value-sets (
   {:benchmark "EUR.6M3M.5Y6M", :bvalue "-0"}), 
 :dimensions (
   {:type "Currency", :dvalue "EUR"} 
   {:type "ValueUnderlying_0", :dvalue "13.199999999998733"})}

{:measure-value-sets (
   {:benchmark "EUR.LIBOR.U4", :bvalue "0.03558586"}), 
 :dimensions (
   {:type "Currency", :dvalue "EUR"} 
   {:type "ValueUnderlying_0", :dvalue "99.76045398474537"})}

... snip...

我有一个类似于上面的数据集,我需要得到基准,bvalue,dvalue的值,有人可以建议迭代这些并杀死这些值的最佳方法吗?

1 个答案:

答案 0 :(得分:2)

假设您的数据集结构为:

(pprint ds)

[{:measure-value-sets
  [{:bvalue "0", :benchmark "EUR.EONIA.6Y"}
   :dimensions                                ; A symbol on its own. Really ?!?
   [{:dvalue "EUR", :type "Currency"}
    {:dvalue "21.59999999999811", :type "ValueUnderlying_0"}]]}
 {:measure-value-sets
  [{:bvalue "-0", :benchmark "EUR.6M3M.5Y6M"}
   :dimensions
   [{:dvalue "EUR", :type "Currency"}
    {:dvalue "13.199999999998733", :type "ValueUnderlying_0"}]]}]

您可以使用以下内容获取所有bvalues:

(map #(-> % :measure-value-sets first :bvalue) ds)

你的第二次评价:

; highly unlikely your structure is correct
(map #(-> % :measure-value-sets (nth 2) second :dvalue) ds)

与:同时:

(map (juxt 
        #(-> % :measure-value-sets first :bvalue) 
        #(-> % :measure-value-sets (nth 2) second :dvalue)) 
  ds)

返回

(["0" "21.59999999999811"] ["-0" "13.199999999998733"])

但是,我认为您提供的结构不正确。