1

以下は、args という名前の架空のハッシュマップです。

{:body {:milestones [{:status 1 :otherValues x} 
                     {:status 2 :otherValues z} 
                     {:status 1 :otherValues y]}}

私の目標は、各 :status キーの値のコレクションを持つことです。それらはすべて、:milestones の子である同じ深さにあります。

私は近づいています。これを行うことで最初のステータスの値を取得する方法を知っています:

(let [{[{:keys [status]} x] :milestones} :body} args]
  (println status))

最終的な目標は、値が 1 の :status を含むマップを見つけ、個々のマップごとに新しいコレクションを作成することです。

これの文字通りの適用は、TeamworkPM に接続し、「遅れている」または「未完了」のステータスを持つマイルストーンを Google カレンダーと同期することです。

このシナリオでは、必要な出力は {1, 2, 1} になります。最終的な目標は、

 {{:status 1 :otherValues x} 
  {:status 1 :otherValues Y}}
4

1 に答える 1

1

map のベクトルを変数に直接分解する方法はわかりませんでしたが、代わりに、最初に の子を取得してから:milestones、基本的なmaporを使用できfilterます。

map を関数として適用することで、 map の値を取得できることに注意してください。(例:の場合mは) {:key1 "val1"}(m :key1)"val1"

(def args {:body {:milestones [{:status 1 :otherValues 'x}
                               {:status 2 :otherValues 'z}
                               {:status 1 :otherValues 'y}]}})

(let [{{x :milestones} :body} args,
        y (map #(% :status) x),
        z (filter #(= (% :status) 1) x)
      ]
      (println x) ; [{:status 1, :otherValues x} {:status 2, :otherValues z} {:status 1, :otherValues y}]
      (println y) ; (1 2 1)
      (println z) ; ({:status 1, :otherValues x} {:status 1, :otherValues y})
  )
于 2014-06-06T00:01:55.463 に答える