2014-02-07 77 views
0
{: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能有人建議最好的方式來遍歷這些殺值是多少?嵌套向量如何獲取值

+0

每個地圖都有2個':dvalue',你想要哪一個?另外我明白你上面的代碼是這些地圖的矢量,對嗎? – m0skit0

+0

第一個dvalue – redhands

+2

該數據集無效Clojure。內部列表不被引用,應該可能是向量。通過「殺」你的意思是刪除? – mac

回答

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) 

而且你的第二個dvalues有:

; 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"]) 

不過,我不認爲你提供的結構是正確的。