Hi,
maybe this does what you want. I'm not sure, since you add the new
meeting to *all* meetings? And where does the :title come from when
you add a new meeting? I assume you have a map of a meeting title and
a meeting and want to add this to the corresponding entry in the data
map. If the meeting is not contained it will be added as n+1.
(defn insert-meeting-data
[data {:keys [title meeting]}]
(if-let [k (some #(when (= title (get-in data [% :title])) %) (keys
data))]
(update-in data [k :meetings] conj meeting)
(let [k (inc (apply max (keys data)))]
(assoc data k {:title title :meetings [meeting]}))))
To be used eg. as:
(reduce insert-meeting-data data sequence-of-title-meeting-maps)
> Also, as a secondary concern, I read on here a while ago that when you
> find yourself typing "((" it's a sign of an issue - how, given the
> data structure I've to work with, woud you access the title of a value
> if not using that "((" syntax, i.e. ((data key) :title)?
(( is not necessarily a sign of an issue, but for your example you can
do (:title (data key)) or (get-in data [key :title]).
> (loop [data (sorted-map)
> collection newData
> meeting (first collection)]
>
> (def key ( .... ))
Almost surely not what you want. You want a let, not a def. def is
always global and in 95% of the cases should only be used in global
context. Exceptions are for example closures.
(let [hidden-atom (atom nil)]
(defn can-access-hidden-atom
[..]
....))
> (if (not (nil? (next collection)
You can save the nil?. (if (not (next collection))) will also work.
nil is logically false.
> (recur (cond (not (nil? (data key)))
> (true? true)
*ieeck* Please do (cond ... :else default-clause). Not true, or (true?
true) or other stuff.
--
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