On Wed, Jan 25, 2012 at 10:45 AM, Simon Holgate <simon.holg...@gmail.com> wrote:
> I've retrieved some data from my database which is returned as a
> clojure.lang.PersistentVector:
> org.psmsl.netcdf.core> res
> [{:name "BREST", :time #<Date 1807-01-01>, :rlrdata 6882M} {:name
> "BREST", :time #<Date 1807-02-01>, :rlrdata 6908M} {:name
> "BREST", :time #<Date 1807-03-01>, :rlrdata 6873M}...{:name
> "BREST", :time #<Date 2008-11-01>, :rlrdata 7140M} {:name
> "BREST", :time #<Date 2008-12-01>, :rlrdata 7088M}]
> org.psmsl.netcdf.core> (class res)
> clojure.lang.PersistentVector
>
> I thought I should be able to do:
> (vals res)

> and
> org.psmsl.netcdf.core> (get res :time)
> returns nil
>
> What am I doing wrong?

>From what I can tell, you want to list the values and extract the
value associated with :time for a map. The problem is that res is not
a map, but a vector of maps. If you want to do these operations on
every map in the vector you can use the map function ("map" as in "to
map"):

    (map vals res)

    (map :time res)

In the last example I made use of the fact that keywords also work as
functions. (:some-keyword some-map) is the same as (get some-map
:some-keyword).

To play in the repl with the first value in the vector in the repl you
can extract it with nth or get:

    user> (def res ...)
    #'res
    user> (def first-res (nth res 0))
    #'first-res
    user> (vals first-res)
    ...
    user> (get first-res :time)
    ...

// raek

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to