-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Dave Tenny wrote:
> If I do something like a describe-instances call in amazonica, I get
> a typical clojure-y set of data fairly deeply nested data structures 
> that I have yet to master with respect to traversing  using basic 
> clojure operations.
> 
> Given a result that basically ends up looking like pages of
> interleaved maps and arrays, what should I be using to pick out 
> nested key/value information?
> 

Hi Dave,

You want to look at extending the IMarshall protocol -- it defines how
the java objects returned by the API are (de?)-serialized into Clojure
datastructures. You can flatten the results massively without much work.
Check the docs, but the examples in the source code are better (as
below). Look at how it's done for some of the API, e.g. S3:

(extend-protocol IMarshall
  S3Object
  (marshall [obj]
    {:bucket-name       (.getBucketName obj)
     :key               (.getKey obj)
     :input-stream      (.getObjectContent obj)
     :object-content    (.getObjectContent obj)
     :redirect-location (.getRedirectLocation obj)
     :object-metadata   (marshall
                          (.getObjectMetadata obj))}))

Note that you can also nest calls recursively if you have to (e.g. some
objects are inexplicably tied to one another -- .getResourceRecordSet
comes to mind). Most calls are just chains of reflection, IIRC, so
indeed there are likely pages of arbitrary nesting.

You're also going to want the amazon java api docs handy in order to
figure out which methods you'll want for which objects you come across.
The REPL & a good autocomplete is invaluable here too.

Cheers,

- ----
Sam Halicke
@samhalicke

> {:reservations [{:reservation-id "r-3da23a55", ... pages of output
> ... }]}]}]} user=>
> 
> 'get-in' won't do it because of the arrays (or PersistentArrayMaps,
> as the case may be). I was hoping to avoid zippers, but maybe that is
> the idiomatic way to do it, I don't know.
> 
> What's the easy way to traverse these things?  This is a very common 
> data pattern in using clojure to access everything from html content
> to AWS data. I just want to pluck out the :instance k/v information
> in the nested morass of data printed at my REPL but I haven't yet
> found the intuitive and idiomatic way to do it.
> 

Yeah, skip traversal and just get the information you want in as flat of
a data structure as you want using the marshalling/coercion bits.


> 
> 
> 
> 
> -- 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 --- You received this
> message because you are subscribed to the Google Groups "Clojure"
> group. To unsubscribe from this group and stop receiving emails from
> it, send an email to clojure+unsubscr...@googlegroups.com 
> <mailto:clojure+unsubscr...@googlegroups.com>. For more options,
> visit https://groups.google.com/d/optout.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBCgAGBQJTIJtaAAoJELjsMLyBmkuqpj0H/132/iCDYvBszN8NBhmx2Ejw
eX8z2yiWWIbwL9XQTFB+/Y7gK1upfsnzgcHGFqXF4Iji+DaqJjGFBn3ad+icQK9i
xSXIlAzSU45azx8iKnI5Jw1/aErYYAJY3WL3bgORLNKikl8P1pPZMt3+N90Bgtn9
UBdvh6/KUwKPJ8gvaI+UBtsQ6dx6HZ5VHRH0O5n54EzciiY+pWL223OynLWlzWOJ
y3gsUuWU9/fTftj6H18nlsCIbCpgV5CDnXbp4HRX8HpjMGAi4ekqwgpDddTBbfYv
7tFs/KJxPzoi7FJgo5qwCJ15u7gy57z1+8Kz9d+6Cap+U73K7y96JzpSvxRfqsk=
=lZZr
-----END PGP SIGNATURE-----

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to