2

Clojure オブジェクト配列があります。次のようなもの:

(def data {
    :genre "fantasy"
    :books [
        { :id 1 :name "Lord of the rings" }
        { :id 2 :name "Game of thrones" }
        { :id 3 :name "Harry potter" }]
    })

本のすべてのIDを取得したい..次のようなもの[1 2 3]

私はいくつかのことを試しました:

  1. (seq (data :books :id))
  2. (data :books) :id) ;results in an error, as expected

しかし、IDの取得方法がわかりません。ID を取得するために dosq やその他のイテレータ関数を使用する必要がありますか?

ありがとう

4

1 に答える 1

6
(->> data :books (map :id))
于 2013-06-10T16:22:26.117 に答える