Thanks all. This just highlights one of the nice things about Clojure to me - the code gets out of the way to allow the algorithm to shine through. Lovely.
By the way, this implementation is closest to my initial although I didn't use juxt at the repl, but I did lose my repl history and can't recall what I did. For me personally, I am learning with each new post so please keep them coming! On Wednesday, November 20, 2013 1:26:43 AM UTC, Joshua Ballanco wrote: > > In an attempt to be slightly more "elegant" (whatever that means ;-) ): > > -----8<-----8<----- > > (def start [{:key 3 :value 10} {:key 6 :value 30}]) > > (into [] (map (fn [[k v]] {:key k :value v}) > (merge > (into {} (for [x (range 6)] {x nil})) > (into {} (map (juxt :key :value) start))))) > > > ;;=> [{:key 6, :value 30} {:key 0, :value nil} {:key 1, :value nil} {:key > 2, :value nil} {:key 3, :value 10} {:key 4, :value nil} {:key 5, :value > nil}] > > -----8<-----8<----- > > Cheers, > > Josh > > > On Tuesday, November 19, 2013 at 2:00 PM, Jim - FooBar(); wrote: > > > On 19/11/13 11:29, Colin Yates wrote: > > > In Java I would do something like: > > > > > > // create a convenient look up to avoid nasty N^2 lookups > > > Map<Object, Object> keyToValue = new HashMap.... > > > for (Map<Object, Object> kvMap: kvSequence) > > > keyToValue.put(kvMap.get("key"), kvMap.put("value")); > > > > > > List<Object> allKeys = calculateAllKeys(); > > > > > > List<Map<Object, Object>> results = new Array.... > > > for (Object key: allKeys) > > > Object result = keyToValue.get(key); // null is fine for missing keys > > > results.put(key, result); > > > > > > return results; > > > > > > this code doesn't do any sorting of keys so I'm not sure it would give > > you the exact desired result you posted... > > > > Jim > > > > -- > > -- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to > > clo...@googlegroups.com<javascript:>(mailto: > clo...@googlegroups.com <javascript:>) > > Note that posts from new members are moderated - please be patient with > your first post. > > To unsubscribe from this group, send email to > > clojure+u...@googlegroups.com <javascript:> (mailto: > clojure+u...@googlegroups.com <javascript:>) > > 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+u...@googlegroups.com <javascript:> (mailto: > clojure+u...@googlegroups.com <javascript:>). > > For more options, visit https://groups.google.com/groups/opt_out. > > > > -- -- 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/groups/opt_out.