Hi Base, Perhaps something like the following:
(defn normalize-creatures [creatures] (letfn [(split [str] (seq (.split str "\\s")))] (for [{:keys [animal sound number-of-feet]} creatures] (map (fn [a s n] {:animal a :sound s :number-of-feet n}) (split animal) (split sound) (split number-of-feet))))) ;; *foo* is the test data you mentioned (normalize-creatures *foo*) => (({:animal "dog" :sound "woof" :number-of-feet "4"} {:animal "cat" :sound "meow" :number-of-feet "4"} {:animal "bird" :sound "chirp" :number-of-feet "2"}) ({:animal "horse" :sound "neeeee" :number-of-feet "4"}) ({:animal "wolf" :sound "howl" :number-of-feet "4"} {:animal "pig" :sound "oink" :number-of-feet "4"})) All the best, Tayssir On Mar 6, 1:07 am, Base <basselh...@gmail.com> wrote: > Hi all - > > I am trying to transofrm a data structure and am kind of stuck. > > I currently have a list of maps > > ( {:animal "dog cat bird" :sound "woof meow chirp" :number-of-feet "4 > 4 2"} > {:animal "horse" :sound "neeeee" :number-of-feet "4"} > {:animal "wolf pig" :sound "howl oink":number-of-feet "4 4"} ) > > and want to trasform it to: > > ( > ({:animal "dog" :sound "woof" :number-of-feet "4" } > {:animal "cat" :sound "meow" :number-of-feet "4"} > {:animal "bird" :sound "chirp" :number-of-feet "2"}) > > ({:animal "horse":sound "neeee" :number-of-feet "4"}) > > ({:animal "wolf" :sound "howl" :number-of-feet "4"} > {:animal "pig" :sound "oink" :number-of-feet "4"}) > ) > > *spacing added for clarity* > > I have tried a few goofy attempts at this that were somewhat > successful. but what I don't like is that most of my attempts (which i > am kind of embarrassed to post) end up looking very un-clojuresque, > and much more imperative looking...and we all know there is a better, > more idiomatic way... > > any help is (as always) most appreciated. > > thanks > > base -- 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